Nu aveti permisiuni pentru a descarca fisierul grader_test5.ok
Cod sursa(job #2330843)
| Utilizator | Data | 28 ianuarie 2019 21:08:23 | |
|---|---|---|---|
| Problema | Radix Sort | Scor | 30 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 1.04 kb |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fi("radixsort.in");
ofstream fo("radixsort.out");
const int BASE = 1e5;
int n, a, b, c;
int v[10000005];
int v2[10000005];
ll cnt[100005];
void radixSort()
{
ll p = 1;
for (int rep = 1; rep <= 2; rep++)
{
memset(cnt, 0, sizeof(cnt));
p *= BASE;
for (int i = 1; i <= n; i++)
cnt[(v[i] / (p / BASE)) % BASE + 1]++;
for (int i = 1; i <= BASE; i++)
cnt[i] += cnt[i - 1];
memset(v2, 0, sizeof(v2));
for (int i = 1; i <= n; i++)
{
int poz = cnt[(v[i] / (p / BASE)) % BASE] + 1;
v2[poz] = v[i];
cnt[(v[i] / (p / BASE)) % BASE]++;
}
memcpy(v, v2, sizeof(v2));
}
}
int main()
{
fi >> n >> a >> b >> c;
v[1] = b;
for (int i = 2; i <= n; i++)
v[i] = (a * v[i - 1] + b) % c;
radixSort();
for (int i = 1; i <= n; i += 10)
fo << v[i] << " ";
return 0;
}
