Cod sursa(job #1146111)

Utilizator supermitelArdelean Razvan Mitel supermitel Data 18 martie 2014 18:35:34
Problema Radix Sort Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.93 kb
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

vector<int> a;
vector<int> lista[256];

int n, A, b, c;

void functie(int gr)
{
        for(int i = 0; i < n; i++)
            lista[a[i] & (255 << (8*gr))].push_back(a[i]);
        a.clear();
        for(int j = 0; j < 256; j++)
        {
            for(int w = 0; w < lista[j].size(); w++)
                a.push_back(lista[j][w]);
            lista[j].clear();
        }
}

void citire()
{
    scanf("%d%d%d%d", &n, &A, &b, &c);
    a.push_back(b);
    for(int i = 1; i < n; i++)
        a.push_back((1ll*A*a.back()+b) % c);
}

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

    citire();
    for(int i = 0; i < 4; i++)
        functie(i);

    for(int i = 0; i < n; i+=10)
        printf("%d ", a[i]);
    printf("\n");
    return 0;
}