Pagini recente » Cod sursa (job #2524163) | Cod sursa (job #845225) | Cod sursa (job #348609) | Cod sursa (job #2131593) | Cod sursa (job #1529573)
#include <fstream>
#include <vector>
using namespace std;
const int MAX_N = 10000002;
int n;
int v[MAX_N];
void radixSort(int n) {
int groupSize = 8;
vector < int > buckets[(1 << groupSize)];
for(int step = 0; step < 32; step += groupSize) {
for(int i = 0; i < (1 << groupSize); ++i) {
buckets[i].clear();
}
for(int i = 0; i < n; ++i) {
buckets[(v[i] & (((1 << groupSize) - 1) << step)) >> step].push_back(v[i]);
}
int k = 0;
for(int i = 0; i < (1 << groupSize); ++i) {
for(int j = 0; j < (int) buckets[i].size(); ++j) {
v[k++] = buckets[i][j];
}
}
}
}
int main() {
ifstream f("radixsort.in");
ofstream g("radixsort.out");
int a, b, c;
f >> n >> a >> b >> c;
v[0] = b;
for(int i = 1; i < n; ++i) {
v[i] = ((1LL * a * v[i - 1]) % c + b) % c;
}
radixSort(n);
for(int i = 0; i < n; i += 10) {
g << v[i] << " ";
}
g << "\n";
f.close();
g.close();
return 0;
}