Cod sursa(job #1842123)

Utilizator bt.panteaPantea Beniamin bt.pantea Data 6 ianuarie 2017 15:34:26
Problema Radix Sort Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.11 kb
#include <iostream>
#include <fstream>
#define NMAX 10000010
using namespace std;
ifstream f ("radixsort.in");
ofstream g ("radixsort.out");

int v[2][NMAX], q[NMAX], n, a, b, c;
int sw = 0;

void RadixSort()
{
    int bit = 0;
    int mij = n;
    while (bit < 32)
    {
        int v0 = 1, v1 = n;
        for (int i = 1; i <= mij; i++)
            if ((v[sw][i] & (1<<bit)))
                v[!sw][v1--] = v[sw][i];
            else
                v[!sw][v0++] = v[sw][i];

        for (int i = n; i > mij; i--)
            if ((v[sw][i] & (1<<bit)))
                v[!sw][v1--] = v[sw][i];
            else
                v[!sw][v0++] = v[sw][i];

        //for (int i = 1; i < v0; i++)
            //v[i] = q[i];
        //for (int i = n + 1; i > v1; i--)
            //v[v0++] = q[i];
        sw = !sw;
        mij = v1;
        bit++;
    }
}

int main()
{
    f>>n>>a>>b>>c;
    v[sw][1] = b % c;
    for (int i = 2; i <= n; i++)
        v[sw][i] = (a * v[sw][i - 1] + b) % c;
    RadixSort();
    for (int i = 1; i <= n; i+=10)
        g<<v[sw][i]<<' ';
    return 0;
}