Pagini recente » Cod sursa (job #1981492) | Cod sursa (job #1625992) | Cod sursa (job #2491591) | Cod sursa (job #1506795) | Cod sursa (job #2803458)
#include <iostream>
#include <fstream>
using namespace std;
const int NMAX = 1e7;
const int BASE = 4096;
const int VALMAX = ( ( 1 << 30 ) - 1 ) * 2 + 1;
int n;
int v[NMAX];
int frecv[BASE];
int aux[NMAX];
void reorder( int xit ) {
int i;
for ( i = 0; i < BASE; i ++ )
frecv[i] = 0;
for ( i = 0; i < n; i ++ )
frecv[v[i] / ( 1 << xit ) % BASE] ++;
for ( i = 1; i < BASE; i ++ )
frecv[i] += frecv[i - 1];
for ( i = n - 1; i >= 0; i -- )
aux[--frecv[v[i] / ( 1 << xit ) % BASE]] = v[i];
for ( i = 0; i < n; i ++ )
v[i] = aux[i];
}
void radix() {
int xit;
for ( xit = 0; xit < 3; xit ++ ) {
reorder( 12 * xit );
}
}
int main() {
ifstream fin( "radixsort.in" );
ofstream fout( "radixsort.out" );
int a, b, c, i, x;
fin >> n >> a >> b >> c;
v[0] = b;
x = b;
for ( i = 1; i < n; i ++ ) {
x = ( (long long)a * x + b ) % c;
v[i] = x;
}
radix();
for ( i = 0; i < n; i += 10 )
fout << v[i] << ' ';
return 0;
}