Pagini recente » Cod sursa (job #1512971) | Cod sursa (job #2531953) | Cod sursa (job #2855729) | Cod sursa (job #3164808) | Cod sursa (job #1245794)
#include <cstdio>
using namespace std;
struct list
{
int inf;
list *urm;
};
list *A[256],*B[256],*aux,**a,**b,**c;
int n,i,j,x,sh,co,fa,fb,fc;
int main()
{
freopen("radixsort.in","r",stdin);
freopen("radixsort.out","w",stdout);
a=A;b=B;
scanf("%d%d%d%d",&n,&fa,&fb,&fc);
x=fb;sh=24;
for(i=1;i<=n;i++)
{
aux=new list;
co=(x>>sh)&255;
aux->inf=x;
aux->urm=a[co];a[co]=aux;
x=(1LL*x*fa+fb)%fc;
}
for(i=1,sh-=8;i<=3;i++,sh-=8)
{
for(j=0;j<256;j++)
{
for(;a[j];)
{
aux=a[j];a[j]=a[j]->urm;
x=aux->inf;delete aux;
co=(x>>sh)&255;
aux=new list;
aux->inf=x;aux->urm=b[co];
b[co]=aux;
}
}
c=a;a=b;b=c;
}
for(i=0,x=10;i<256;i++)
for(aux=a[i];aux;aux=aux->urm)
{
if(x==10)
{
printf("%d ",aux->inf);
x=0;
}
x++;
}
return 0;
}