Mai intai trebuie sa te autentifici.
Cod sursa(job #2052025)
Utilizator | Data | 29 octombrie 2017 21:13:59 | |
---|---|---|---|
Problema | Radix Sort | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 1.11 kb |
#include <cstdio>
#include <cstring>
using namespace std;
int v[10000001], myoutput[10000001];
void mysort(int n, long long zece) {
int mycount[10];
memset(mycount, 0, sizeof(mycount));
for(int i = 1; i <= n; ++ i) {
int p = (1LL * v[i] % zece) / (zece / 10);
mycount[p] ++;
}
for(int i = 1; i <= 9; ++ i) {
mycount[i] += mycount[i - 1];
}
for(int i = n; i >= 1; -- i) {
int p = (1LL * v[i] % zece) / (zece / 10);
myoutput[mycount[p]] = v[i];
mycount[p] --;
}
for(int i = 1; i <= n; ++ i) {
v[i] = myoutput[i];
}
}
int main() {
freopen("radixsort.in", "r", stdin);
freopen("radixsort.out", "w", stdout);
int n, a, b, c;
scanf("%d%d%d%d", &n, &a, &b, &c);
v[1] = b;
for(int i = 2; i <= n; ++ i) {
v[i] = (1LL * a * v[i - 1] + b) % c;
}
long long zece = 10;
for(int cif = 1; cif <= 10; ++ cif, zece *= 10) {
mysort(n, zece);
}
for(int i = 1; i <= n; i += 10) {
printf("%d ", v[i]);
}
return 0;
}