Cod sursa(job #2031469)

Utilizator mateibanuBanu Matei Costin mateibanu Data 3 octombrie 2017 11:25:36
Problema Radix Sort Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <stdio.h>
#include <queue>
using namespace std;

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

ll v[10000001];
ll n,a,b,c,nr,i,mx=0,z,k,j;
queue<ll>l[256];

int main()
{
    fscanf(f,"%lld%lld%lld%lld",&n,&a,&b,&c);
    nr=b;
    for (i=1;i<=n;i++){
        v[i]=nr;
        nr=(a*nr+b)%c;
        if (v[i]>mx) mx=v[i];
    }
    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;j++)

            while (!l[j].empty()){
                k++;
                v[k]=l[j].front();
                l[j].pop();
            }
    }
    for (i=1;i<=n;i+=10) fprintf(g,"%lld ",v[i]);
    fclose(f);
    fclose(g);
    return 0;
}