Cod sursa(job #2368197)

Utilizator Valentin0709Datcu George Valentin Valentin0709 Data 5 martie 2019 14:31:47
Problema Radix Sort Scor 70
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[256];

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 <= 24; i += 8) {
        for(j = 1; j <= n; j++)
            l[(v[j]>>i)&255].push(v[j]);
        k = 0;
        for (j = 0; j <= 255 && 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;

}