Cod sursa(job #2410080)

Utilizator LucaSeriSeritan Luca LucaSeri Data 19 aprilie 2019 18:27:18
Problema Radix Sort Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include <bits/stdc++.h>
 
using namespace std;
 
ifstream f("radixsort.in");
ofstream g("radixsort.out");
 
int v[10000010];
queue<int> radix[256];
 
int get_byte(int x, int i){
    x = (x>>8*i);
    return (x&0xFF);
}
int main(){
    int n, a, b, c;
    f >> n >> a >> b >> c;
    v[1] = b;
    for(int i = 2; i <= n; ++i){
        v[i] = (1LL*a*v[i-1]+b)%c;
    }
 
    for(int i = 0; i < 4; ++i){
        for(int j = 1; j <= n; ++j){
            radix[get_byte(v[j], i)].push(v[j]);
        }
 
        int ind = 0;
 
        for(int j = 0; j <= 255 && ind < n; ++j){
            while(radix[j].size()){
                ++ind;
                v[ind] = radix[j].front();
                radix[j].pop();
            }
        }
    }
 
    for(int i = 1; i <= n; i += 10) g << v[i] << ' ';
    return 0;
}