Cod sursa(job #2416298)

Utilizator GoogalAbabei Daniel Googal Data 27 aprilie 2019 12:29:20
Problema Radix Sort Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.88 kb
#include <bits/stdc++.h>

#define nm 10000010
#define buckets 257

using namespace std;

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

int n, a, b, c;
int v[nm];
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;

    in >> 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)
        out << v[i] <<' ';

    return 0;
}