Cod sursa(job #1156758)

Utilizator rockerboyHutter Vince rockerboy Data 27 martie 2014 23:00:05
Problema Radix Sort Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include <fstream>
#include <vector>
#include <cstring>

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

typedef unsigned int ULL;
typedef vector<ULL> Vektor;
typedef vector<ULL>::iterator Iterator;

ULL x[10000002];
ULL n, a, b, c, i, j;
Iterator it;

void asd (int i)
{
    vector<ULL> temp[256];

    for (j = 1; j<=n; j++)
    {
        temp[(x[j]>>i)&255].push_back(x[j]);
    }
    n = 0;
    for (j=0; j<256; j++)
    {
        for (it = temp[j].begin(); it<temp[j].end(); it++)
        {
            n++;
            x[n] = *it;
        }
    }
}

void radixsort()
{
    for (i=0; i<32; i+=8)
        asd (i);
}



int main()
{
    f >> n >> a >> b >> c;
    x[1] = b;

    for (i=2; i<=n; i++)
    {
        x[i] = (1LL*x[i-1]*a+b)%c;
    }

    radixsort ();

    for (i=1; i<=n; i+=10)
        g << x[i] << " ";
}