Cod sursa(job #1156694)

Utilizator rockerboyHutter Vince rockerboy Data 27 martie 2014 21:47:27
Problema Radix Sort Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <fstream>
#include <algorithm>
#include <vector>
#include <cstring>

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

typedef unsigned long long ULL;
typedef vector<ULL> Vektor;
typedef vector<ULL>::iterator Iterator;
typedef vector<ULL>::const_iterator cIterator;

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

void asd (int i)
{
    Vektor 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] = (x[i-1]*a+b)%c;
    }

    radixsort ();

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