码迷,mamicode.com
首页 > 其他好文 > 详细

URAL - 1792 Hamming Code(枚举)

时间:2015-04-21 09:45:52      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

 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 figure

Output

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

input output
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

直接枚举

#include<iostream>
using 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];
		}	
	}
}



URAL - 1792 Hamming Code(枚举)

标签:

原文地址:http://blog.csdn.net/qq_18738333/article/details/45157139

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!