Cod sursa(job #1156683)

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

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

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

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

void asd (int i)
{
    Vektor temp[2];

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

}

void radixsort()
{
    for (i=0; i<30; i++)
        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 ();
    //sort (x+1, x+n+1);

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