Pagini recente » Cod sursa (job #1208111) | Cod sursa (job #1069595) | Cod sursa (job #1547114) | Cod sursa (job #1143624) | Cod sursa (job #1732911)
#include <iostream>
#include <fstream>
using namespace std;
const int nmax = 10000001;
int a[nmax];
int temp[nmax];
int counts[257];
int *ap, *tempp, *aux;
int n;
int A,B,C;
int i;
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
void radixSort();
int main()
{
fin >> n;
fin >> A >> B >> C;
a[0] = B%C;
for(int i=1; i<n; i++)
{
a[i] = (1LL * A * a[i-1] % C + B)%C;
}
ap = a;
tempp = temp;
radixSort();
for(int i=0; i<n; i+=10)
{
fout << ap[i] << " ";
}
fin.close();
fout.close();
return 0;
}
void radixSort()
{
for(int digit = 0; digit <4; digit++)
{
for( i=0;i<256; i++)
counts[i] =0;
for(i=0; i<n; i++)
counts[(ap[i]>>(digit*8))&255]++;
for(i=1; i<256; i++)
counts[i] +=counts[i-1];
for(i=n-1; i>=0; i--)
{
tempp[counts[(ap[i]>>(digit*8))&255]-1] = ap[i];
counts[(ap[i]>>(digit*8))&255]--;
}
aux = tempp;
tempp = ap;
ap = aux;
}
}