Cod sursa(job #2216789)

Utilizator VladTiberiuMihailescu Vlad Tiberiu VladTiberiu Data 27 iunie 2018 22:15:18
Problema Radix Sort Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.03 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("radixsort.in");
ofstream g("radixsort.out");

const int NMax = 10000003;

struct number{
    unsigned char dig[4];
};

unsigned int n,A,B,C;
unsigned int c[(1 << 8) + 1];
unsigned int a[NMax],b[NMax];

int main()
{
    f >> n >> A >> B >> C;
    a[1] = B;
    for(int i = 2; i <= n; ++i){
        a[i] = (A * a[i - 1] + B) % C;
    }

    for(int i = 0; i < 4; ++i){
        for(int j = 0; j < (1 << 8); ++j){
            c[j] = 0;
        }
        for(int j = 1; j <= n; ++j){
            c[(int)(((number*)&a[j])->dig[i])] ++;
        }
        for(int j = 1; j < (1 << 8); ++j){
            c[j] = c[j - 1] + c[j];
        }
        for(int j = n; j >= 1; --j){
            b[c[(int)(((number*)&a[j])->dig[i])]] = a[j];
            c[(int)(((number*)&a[j])->dig[i])]--;
        }
        for(int j = 1; j <= n; ++j){
            a[j] = b[j];
        }
    }
    for(int i = 1; i <= n; i += 10){
        g << a[i] << ' ';
    }

    return 0;
}