Pagini recente » Cod sursa (job #1582631) | Cod sursa (job #1327852) | Cod sursa (job #2228403) | Cod sursa (job #488442) | Cod sursa (job #2672597)
// Tema Excelenta.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <fstream>
#include <iostream>
using namespace std;
ifstream in("radixsort.in");
ofstream out("radixsort.out");
int n, a, b, c;
int v[10000010];
int Ordine_curenta[10000010];
int f[1 << 16 + 5];
void _read(){
in >> n >> a >> b >> c;
v[1] = b;
for (int i = 2; i <= n; ++i)
v[i] = (1LL * a * v[i - 1] + b) % c;
}
void radix(){
int mask = (1 << 16) - 1;
for (int bits = 0; bits < 32; bits += 16){
for (int i = 0; i <= mask + 5; ++i)
f[i] = 0;
for (int i = 1; i <= n; ++i){
int Numar_curent = (v[i] >> bits) & mask;
f[Numar_curent]++;
}
for (int i = 1; i <= mask; ++i)
f[i] += f[i - 1];
for (int i = n; i >= 1; --i){
int Numar_curent = (v[i] >> bits) & mask;
Ordine_curenta[f[Numar_curent]--] = v[i];
}
for (int i = 1; i <= n; ++i)
v[i] = Ordine_curenta[i];
}
}
int main(){
_read();
radix();
for (int i = 1; i <= n; i += 10)
out << v[i] << " ";
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file