Pagini recente » Cod sursa (job #2087332) | Cod sursa (job #2188934) | Cod sursa (job #1832535) | Cod sursa (job #374902) | Cod sursa (job #2836335)
#include <bits/stdc++.h>
using namespace std;
ifstream in("radixsort.in");
ofstream out("radixsort.out");
long long n,A,B,C;
queue<int>ant[260],act[260];
int main()
{
in >> n >> A >> B >> C;
ant[1].push(B);
for (int i = 1; i < n; i++)
{
long long nr = (A * ant[1].back() + B) % C;
ant[1].push(nr);
}
int p256 = 1;
for (int q = 0; q <= 3; q++)
{
for (int i = 0; i < 256; i++)
while (ant[i].size())
{
act[(ant[i].front() / p256) & 255].push(ant[i].front());
ant[i].pop();
}
for (int i = 0; i < 256; i++)
{
while (act[i].size())
{
ant[i].push(act[i].front());
act[i].pop();
}
}
if (q != 3)
p256 *= 256;
}
int u = 0;
for (int i = 0; i < 256; i++)
{
while (ant[i].size())
{
u++;
if (u == 10)
u = 0;
if (u == 1)
out << ant[i].front() << ' ';
ant[i].pop();
}
}
return 0;
}
/*
#include <bits/stdc++.h>
using namespace std;
ifstream in("radixsort.in");
ofstream out("radixsort.out");
long long n,A,B,C;
vector<int>ant[260],act[260];
int main()
{
in >> n >> A >> B >> C;
ant[1].push_back(B);
for (int i = 1; i < n; i++)
{
long long nr = (A * ant[1][i - 1] + B) % C;
ant[1].push_back(nr);
}
int p256 = 1;
for (int q = 0; q <= 3; q++)
{
for (int i = 0; i < 256; i++)
for (int j = 0; j < ant[i].size(); j++)
act[(ant[i][j] / p256) & 255].push_back(ant[i][j]);
for (int i = 0; i < 256; i++)
ant[i].clear();
for (int i = 0; i < 256; i++)
{
reverse(act[i].begin(),act[i].end());
while (act[i].size())
{
ant[i].push_back(act[i][act[i].size() - 1]);
act[i].pop_back();
}
}
if (q != 3)
p256 *= 256;
}
int u = 0;
for (int i = 0; i < 256; i++)
{
for (int j = 0; j < ant[i].size(); j++)
{
u++;
if (u == 10)
u = 0;
if (u == 1)
out << ant[i][j] << " ";
}
}
return 0;
}
*/