Pagini recente » Cod sursa (job #1932169) | Cod sursa (job #2523865) | Cod sursa (job #1798367) | Cod sursa (job #1026205) | Cod sursa (job #3220808)
#include <iostream>
#include <fstream>
#include <stdint.h>
const uint32_t WORD_SIZE_LOG_2 = 8;
const uint32_t WORD_SIZE = 1 << WORD_SIZE_LOG_2;
const uint32_t WORD_COUNT = 4;
const uint32_t MAX_N = 10000000;
uint32_t vec[MAX_N];
uint32_t vec2[MAX_N];
int main() {
std::ifstream fin("radixsort.in");
std::ofstream fout("radixsort.out");
uint32_t n, a, b, c;
fin >> n >> a >> b >> c;
vec[0] = b;
for(uint32_t i = 1; i != n; ++i)
vec[i] = ((uint64_t)a * vec[i - 1] + b) % c;
for(uint32_t i = 0; i != WORD_COUNT; ++i) {
uint32_t starts[WORD_SIZE];
for(uint32_t j = 0; j != WORD_SIZE; ++j)
starts[j] = 0;
for(uint32_t j = 0; j != n; ++j) {
uint32_t word = (vec[j] >> (WORD_SIZE * i)) & (WORD_SIZE - 1);
if(word != WORD_SIZE - 1)
++starts[word + 1];
}
for(uint32_t j = 2; j != WORD_SIZE; ++j)
starts[j] += starts[j - 1];
for(uint32_t j = 0; j != n; ++j) {
uint32_t word = (vec[j] >> (WORD_SIZE * i)) & (WORD_SIZE - 1);
vec2[starts[word]++] = vec[j];
}
for(uint32_t j = 0; j != n; ++j)
vec[j] = vec2[j];
}
for(uint32_t i = 0; i < n; i += 10)
fout << vec[i] << ' ';
fin.close();
fout.close();
return 0;
}