Submit Status
Description
Let us consider four disks intersecting as in the figure. Each of the three shapes formed by the intersection of three disks will be called apetal. Write zero or one on each of the disks. Then write on each petal the remainder in the division by two of the sum of integers on the disks that contain this petal. For example, if there were the integers 0, 1, 0, and 1 written on the disks, then the integers written on the petals will be 0, 1, and 0 (the disks and petals are given in the order shown in the figure). This scheme is called a Hamming code. It has an interesting property: if you enemy changes secretely any of the seven integers, you can determine uniquely which integer has been changed. Solve this problem and you will know how this can be done.Input
The only line contains seven integers separated with a space, each of them being zero or one. The first four integers are those written on the disks in the order shown in the figure. The following three integers are those written on the petals in the order shown in the figureOutput
Output one line containing seven integers separated with a space. The integers must form a Hamming code. The set of integers may differ from the input set by one integer at most. It is guaranteed that either the input set is a Hamming code or a Hamming code can be obtained from it by changing exactly one integer.Sample Input
0 1 0 1 1 0 1
0 1 0 0 1 0 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
直接枚舉
#includeusing namespace std; int a[10]; bool ok(int a1, int a2, int a3, int a4, int b1,int b2, int b3) { if ((a1 + a2 + a4) % 2 != b3) return false; if ((a1 + a3 + a4) % 2 != b2) return false; if ((a2 + a3 + a4) % 2 != b1) return false; return true; } int main() { while (cin>>a[0]) { for (int i = 1; i < 7; i++) cin >> a[i]; if (ok(a[0], a[1], a[2], a[3], a[4], a[5], a[6])) { for (int i = 0; i < 7; i++) { if (i) cout << " "; cout << a[i]; } cout << endl; continue; } for (int i = 0; i < 7; i++) { a[i] = 1^a[i]; if (ok(a[0], a[1], a[2], a[3], a[4], a[5], a[6])) { for (int i = 0; i < 7; i++) { if (i) cout << " "; cout << a[i]; } cout << endl; break; } a[i] = 1^a[i]; } } }