Cod sursa(job #1714762)

Utilizator RaduMirceaAndreiRadu Mircea Andrei RaduMirceaAndrei Data 9 iunie 2016 12:32:15
Problema Radix Sort Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
# include <fstream>
# define DIM 10000010
using namespace std;
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
int v[DIM],sol[DIM],f[300],n,a,b,c,i,maxim;
long long l,p;
int main () {
    fin>>n>>a>>b>>c;
    v[1]=b;
    for(i=2;i<=n;i++){
        l=a*1LL*v[i-1]%c;
        l+=b;
        l%=c;
        v[i]=l;
        if(v[i]>maxim)
            maxim=v[i];
    }
    for(i=1;i<=4;i++){
        for(i=0;i<256;i++)
            f[i]=0;
        for(i=1;i<=n;i++)
            f[(v[i]>>p)&255]++;
        for(i=1;i<256;i++)
            f[i]+=f[i-1];
        for(i=n;i>=1;i--)
            sol[f[(v[i]>>p)&255]--]=v[i];
        for(i=1;i<=n;i++)
            v[i]=sol[i];
        p+=8;
    }
    for(i=1;i<=n;i+=10)
        fout<<sol[i]<<" ";
    fout<<"\n";
    return 0;
}