Cod sursa(job #1934663)

Utilizator GoogalAbabei Daniel Googal Data 21 martie 2017 18:28:55
Problema Radix Sort Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.86 kb
#include <bits/stdc++.h>
#define nm 10000010
#define buckets 257

using namespace std;

ifstream fin("radixsort.in");
ofstream fout("radixsort.out");

int v[nm],n,a,b,c;
deque < int > coada[buckets];

void solve(int &n)
{
    int x,j,zz,i;
    for(x = 0; x < 4; x++)
    {
        for( j = 1; j <= n; j++)
        {
            int y = (v[j] >> (8 * x)) & 255;
            coada[y].push_back(v[j]);
        }
        for( zz = 0,i = 0; i < 256; i++)
            while(!coada[i].empty())
            {
                v[++zz] = coada[i].front();
                coada[i].pop_front();
            }
    }
}

int main()
{
    int i;
    fin >> n >> a >> b >> c;
    v[1] = b;
    for(i = 2; i <= n; i++)
        v[i] = (1LL * a * v[i - 1] + b) % c;
    solve(n);
    for(i = 1; i <= n; i+= 10)
        fout << v[i] <<' ';

    return 0;
}