Cod sursa(job #1189413)

Utilizator timicsIoana Tamas timics Data 22 mai 2014 20:00:14
Problema Radix Sort Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include<stdio.h>
#include<vector>
using namespace std;
int N,A,B,C,MOD=255;
vector<int> r[256],v;

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

//freopen("input.txt","r",stdin);

    scanf("%d%d%d%d",&N,&A,&B,&C);
    v.push_back(B);
    for(int i=1;i<N;++i) {
         v.push_back((1LL*A * v[i-1] + B) % C);
    }

    for(int i=0;i<4;++i) {
        for(int j=0;j<v.size();++j) {
            r[((v[j]&MOD)>>(8*i))].push_back(v[j]);
        }
        v.clear();
        for(int j=0;j<255;++j) {
            for(int k=0;k<r[j].size();++k) {
                v.push_back(r[j][k]);
            }
            r[j].clear();
        }

        if(i==2) {
            MOD = MOD<<7;
            MOD -= (1<<23);
            continue;
        }
        MOD = MOD<<8;
    }

    for(int i=0;i<N;i+=10) {
        printf("%d ",v[i]);
    }
    return 0;
}