Pagini recente » Cod sursa (job #593064) | Cod sursa (job #281199) | Cod sursa (job #697955) | Cod sursa (job #1849920) | Cod sursa (job #1156695)
#include <fstream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
ifstream f("radixsort.in");
ofstream g("radixsort.out");
typedef unsigned long long ULL;
typedef vector<ULL> Vektor;
typedef vector<ULL>::iterator Iterator;
typedef vector<ULL>::const_iterator cIterator;
ULL x[10000005];
ULL n, a, b, c, i, j, temp;
Iterator it;
void asd (int i)
{
Vektor temp[256];
for (j = 1; j<=n; j++)
{
temp[(x[j]>>i)&255].push_back(x[j]);
}
n = 0;
for (j=0; j<256; j++)
{
for (it = temp[j].begin(); it<temp[j].end(); it++)
{
n++;
x[n] = *it;
}
temp[j].clear();
}
}
void radixsort()
{
for (i=0; i<=32; i+=8)
asd (i);
}
int main()
{
f >> n >> a >> b >> c;
x[1] = b;
for (i=2; i<=n; i++)
{
x[i] = (x[i-1]*a+b)%c;
}
radixsort ();
for (i=1; i<=n; i+=10)
g << x[i] << " ";
}