Pagini recente » Cod sursa (job #2665803) | Cod sursa (job #3191990) | Cod sursa (job #3253073) | Cod sursa (job #16973) | Cod sursa (job #2208427)
import java.io.*;
import java.util.StringTokenizer;
public class Main {
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
static int[] v = new int[10000000];
static int[] count = new int[1<<8];
static int[] tmp = new int[10000000];
public static void main(String[] args) {
try {
InputStream targetStream = new FileInputStream(new File("radixsort.in"));
InputReader input = new InputReader(targetStream);
int N = input.nextInt(), A = input.nextInt(), B = input.nextInt(), C = input.nextInt();
v[0] = B; tmp[0] = v[0];
for (int i = 1 ; i < N ; ++i){
v[i] = (int)((1L * v[i-1] * A + B) % C);
tmp[i] = v[i];
//System.out.println(v[i]);
}
for (int k = 0 ; k < 4 ; ++k){
for (int i = 0 ; i < N ; ++i) {
v[i] = tmp[i];
int bucket = (v[i] >> (k << 3)) % (1 << 8);
count[bucket]++;
}
for (int i = (1 << 8) - 1 ; i > 0 ; --i){
count[i] = count[i-1];
}
count[0] = 0;
for (int i = 2 ; i < (1 << 8) ; ++i){
count[i] += count[i-1];
}
for (int i = 0 ; i < N ; ++i){
int bucket = (v[i] >> (k << 3)) % (1 << 8);
tmp[count[bucket]] = v[i];
count[bucket]++;
}
for (int i = 0 ; i < (1 << 8) ; ++i){
count[i] = 0;
}
}
OutputStream sinkTarget = new FileOutputStream(new File("radixsort.out"));
PrintWriter output = new PrintWriter(sinkTarget);
for (int i = 0 ; i < N ; i += 10) {
output.printf("%d " , tmp[i]);
}
output.printf("\n");
output.close();
}
catch (IOException e) {}
}
}