Cod sursa(job #1444731)

Utilizator MihaiEMihaiE MihaiE Data 30 mai 2015 09:28:36
Problema Radix Sort Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#define step1 5000000
#define step2 1000000000
#define step3 1500000000
using namespace std;
long long a,b,c,x,y;
int i,j,n,nr=0,bb=1;
vector <int> d[5];
int main(){
freopen("radixsort.in","r",stdin);
freopen("radixsort.out","w",stdout);
scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
y=b;
if (y<=step1) d[1].push_back(y); else
if (y<=step2) d[2].push_back(y); else
if (y<=step3) d[3].push_back(y); else
d[4].push_back(y);
for (i=2;i<=n;i++){
    x=(a*y+b)%c; y=x;
    if (x<=step1) d[1].push_back(x); else
    if (x<=step2) d[2].push_back(x); else
    if (x<=step3) d[3].push_back(x); else
    d[4].push_back(x);

}
for (i=1;i<=4;i++){
    sort(d[i].begin(),d[i].end());
    for (j=0;j<d[i].size();j++){
        nr++;
        if (nr==bb) printf("%d ",d[i][j]),bb+=10;
    }
}
return 0;
}