Pagini recente » Cod sursa (job #2528497) | Cod sursa (job #2819278) | Cod sursa (job #213678) | Cod sursa (job #1372020) | Cod sursa (job #1976058)
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
ifstream in("radixsort.in");
ofstream out("radixsort.out");
#define pb push_back
#define ll long long
const int NMax = 1e7 + 5;
const int inf = 1e9 + 5;
const int nrBytes = 4;
const int Radix = 0xFF;
ll N,A,B,C;
int v1[NMax],v2[NMax];
void countingSort(int*,int*,int);
int main() {
in>>N>>A>>B>>C;
v1[1] = B;
//A %= C;
//B %= C;
for (int i=2;i <= N;++i) {
v1[i] = (A * v1[i-1] + B) % C;
}
for (int i=1;i <= nrBytes;++i) {
if (i & 1) {
countingSort(v1,v2,i-1);
}
else {
countingSort(v2,v1,i-1);
}
}
for (int i=1;i <= N;i += 10) {
out<<v1[i]<<' ';
}
in.close();out.close();
return 0;
}
void countingSort(int* one,int* two,int pw) {
int occ[(1<<8) + 5] = {};
for (int i=1;i <= N;++i) {
++occ[(one[i]>>(pw*8)) & Radix];
}
int total = 0;
for (int i=0;i <= Radix;++i) {
int old = occ[i];
occ[i] = total + 1;
total += old;
}
for (int i=1;i <= N;++i) {
two[occ[(one[i]>>(pw*8)) & Radix]++] = one[i];
}
}