-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhamming.java
More file actions
69 lines (62 loc) · 1.45 KB
/
Copy pathhamming.java
File metadata and controls
69 lines (62 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
ID: 001207j1
LANG: JAVA
TASK: hamming
*/
import java.io.*;
import java.util.*;
public class hamming {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new FileReader("hamming.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("hamming.out")));
String[] s = f.readLine().split(" ");
int[] q = new int[(int) Math.pow(2, 8)];
Arrays.fill(q, -2);
int l = 0;
int N = Integer.parseInt(s[0]), B = Integer.parseInt(s[1]), D = Integer.parseInt(s[2]);
int max = (int) Math.pow(2, B) - 1;
// for (int i = 0; i <= max-N; i++)
for (int i = 0; i <= max; i++) {
if (l == N)
break;
boolean gd = true;
for (int j = 0; j < l; j++) {
if (d(i, q[j]) < D)
gd = false;
}
if (gd)
q[l++] = i;
}
for (int i = 0; i < q.length; i++) {
if (q[i] == -2)
break;
if (q[i + 1] == -2)
out.print(q[i]);
else if ((i + 1) % 10 == 0)
out.println(q[i]);
else
out.print(q[i] + " ");
}
out.println();
f.close();
out.close();
}
public static int d(int i, int j) {// distance
int d = 0;
String s1 = (Integer.toBinaryString(i)), s2 = Integer.toBinaryString(j);
String m, n;
if (Math.max(s1.length(), s2.length()) == s1.length()) {
m = s1;
n = s2;
} else {
m = s2;
n = s1;
}
for (; n.length() < m.length();)
n = "0" + n;
for (int x = 0; x < m.length(); x++)
if (m.charAt(x) != n.charAt(x))
d++;
return d;
}
}