Cod sursa(job #1193292)

Utilizator ZenusTudor Costin Razvan Zenus Data 31 mai 2014 13:47:55
Problema Radix Sort Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

#define NMAX 10000001
#define LL long long

deque < LL > H[10];
LL V[NMAX];
LL A,B,C,N,i,X;

void Radix_sort()
{
    LL Y=1,i;
    deque < LL > :: iterator it;

    for (Y=1;Y<=(LL)(pow(10.0,9))+1;Y*=10)
    {
        for (i=0;i<=9;++i) while (!H[i].empty()) H[i].pop_back();

        for (i=1;i<=V[0];++i)
        H[(V[i]/Y)%10].push_back(V[i]);

        V[0]=0;

        for (i=0;i<=9;++i)
           for (it=H[i].begin();it!=H[i].end();++it)
           V[++V[0]]=*it;
    }
}

int main()
{
freopen("radixsort.in","r",stdin);
freopen("radixsort.out","w",stdout);

scanf("%d%d%d%d",&N,&A,&B,&C);

V[0]=1;
V[V[0]]=B;
for (i=2;i<=N;++i)
V[++V[0]]=(A*V[V[0]-1]+B)%C;

//Radix_sort();
sort(V+1,V+V[0]+1);

for (i=1;i<=V[0];i+=10) printf("%d ",V[i]);
printf("\n");

return 0;
}