Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

枚举一列就可以了,其他的都可以唯一确定,到最后一行再判断下是否可行就完成

Posted by KatrineYang at 2016-08-17 03:30:48 on Problem 1222
#include <stdio.h>

int main() {
	int cases;
	scanf("%d", &cases);
	for(int ii = 0; ii < cases; ii++){
		printf("PUZZLE #%d\n", ii+1);
		int init[5][6];
		for(int i = 0; i < 5; i++)
			for(int j = 0; j < 6; j++)
				scanf("%d", &init[i][j]);
		int res[5][6];
		for(int st = 0; st < 32; st++){
			for(int i = 0; i < 5; i++){
				res[i][0] = ((st & (1<<i)) != 0);
			}
			res[0][1] = (res[0][0]+res[1][0]+init[0][0])%2;
			res[1][1] = (res[0][0]+res[1][0]+res[2][0]+init[1][0])%2;
			res[2][1] = (res[1][0]+res[2][0]+res[3][0]+init[2][0])%2;

			res[3][1] = (res[2][0]+res[3][0]+res[4][0]+init[3][0])%2;

			res[4][1] = (res[3][0]+res[4][0]+init[4][0])%2;

			for(int i = 1; i < 5; i++){
				res[0][i+1] = (res[0][i]+res[0][i-1]+res[1][i]+init[0][i])%2;
				res[1][i+1] = (res[1][i]+res[1][i-1]+res[0][i]+res[2][i]+init[1][i])%2;
				res[2][i+1] = (res[2][i]+res[2][i-1]+res[1][i]+res[3][i]+init[2][i])%2;
				res[3][i+1] = (res[3][i]+res[3][i-1]+res[2][i]+res[4][i]+init[3][i])%2;
				res[4][i+1] = (res[4][i]+res[4][i-1]+res[3][i]+init[4][i])%2;
			}

			bool ok0, ok1, ok2, ok3, ok4;
			ok0 = (res[0][4]+res[0][5]+res[1][5]+init[0][5])%2==0;
			ok1 = (res[1][4]+res[0][5]+res[1][5]+res[2][5]+init[1][5])%2==0;
			ok2 = (res[2][4]+res[1][5]+res[2][5]+res[3][5]+init[2][5])%2==0;
			ok3 = (res[3][4]+res[2][5]+res[3][5]+res[4][5]+init[3][5])%2==0;
			ok4 = (res[4][4]+res[3][5]+res[4][5]+init[4][5])%2==0;
			if(ok0 && ok1 && ok2 && ok3 && ok4){
				for(int i = 0; i < 5; i++){
					for(int j = 0; j < 6; j++){
						printf("%d", res[i][j]);
						if(j != 5) printf(" ");
					}
					printf("\n");
				}
				break;
			}
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator