Pagini recente » Cod sursa (job #1263171) | Clasament speed3 | Cod sursa (job #935140) | Cod sursa (job #2382801) | Cod sursa (job #2222992)
#include <iostream>
#include <fstream>
#define NMAX 10000002
#define mask ((1<<8)-1)
using namespace std;
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
int n, a, b, c;
int numberList[NMAX], semiSorted[NMAX];
int largestNum = 0;
void Read(void)
{
fin >> n >> a >> b >> c;
numberList[1] = b % c;
for (int i = 2; i <= n; i++)
{
numberList[i] = (1LL * a * numberList[i - 1] % c + b) % c;
}
}
void RadixSort(void)
{
for (int p = 0; p < 32; p += 8)
{
int bucket[mask + 10] = { 0 };
for (int i = 1;i <= n;i++)
bucket[(numberList[i] >> p)&mask]++;
for (int i = 1;i <= mask;i++)
bucket[i] += bucket[i - 1];
for (int i = n; i > 0;i--)
semiSorted[bucket[(numberList[i] >> p)&mask]--] = numberList[i];
for (int i = 1; i <= n; i++)
{
numberList[i] = semiSorted[i];
}
}
}
void Print(void)
{
for (int i = 1; i <= n; i += 10)
{
fout << numberList[i] << ' ';
}
}
int main(void)
{
Read();
RadixSort();
Print();
return 0;
}