Cod sursa(job #2368189)

Utilizator Valentin0709Datcu George Valentin Valentin0709 Data 5 martie 2019 14:29:47
Problema Radix Sort Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <bits/stdc++.h>
using namespace std;

FILE * f = fopen("radixsort.in","r");
FILE * g = fopen("radixsort.out","w");

int v[10000001];
int n,a,b,c,i,k,j;
queue<int> l[512];

int main() {

    fscanf(f,"%d%d%d%d",&n,&a,&b,&c);

    v[1] = b;
    for(i = 2; i <= n; i++)
        v[i] = (1ll * a * v[i-1] + b) %c;

    for(i = 0; i <= 48; i += 16) {
        for(j = 1; j <= n; j++)
            l[(v[j]>>i)&511].push(v[j]);
        k = 0;
        for(j = 0; j <= 511 && k < n; j++)
            while(!l[j].empty()){
                k++;
                v[k] = l[j].front();
                l[j].pop();
            }
    }

    for(i = 1; i <= n; i += 10) fprintf(g,"%d ",v[i]);

    fclose(f); fclose(g);

    return 0;
}