Pagini recente » Cod sursa (job #1544300) | Cod sursa (job #2674368) | Cod sursa (job #2610631) | Cod sursa (job #521534) | Cod sursa (job #2224877)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int MAXBIT = 1 << 16;
vector<int> num, counting[MAXBIT];
int main()
{
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
int n, a, b, c;
fin >> n >> a >> b >> c;
long long mask = (1LL << 16) - 1;
num.push_back(b);
for(int i = 1; i < n; ++i)
num.push_back((a * num[i - 1] + b) % c);
for(int i = 0; i < n; ++i){
int pos = num[i] & mask;
counting[pos].push_back(num[i]);
}
num.clear();
for(int i = 0; i < MAXBIT; ++i){
for(int j = 0; j < counting[i].size(); ++j)
num.push_back(counting[i][j]);
counting[i].clear();
}
mask <<= 16;
for(int i = 0; i < n; ++i){
int pos = num[i] & mask;
pos >>= 16;
counting[pos].push_back(num[i]);
}
num.clear();
for(int i = 0; i < MAXBIT; ++i){
for(int j = 0; j < counting[i].size(); ++j)
num.push_back(counting[i][j]);
}
for(int i = 0; i < n; i += 10)
fout << num[i] << " ";
return 0;
}