欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

关灯

程序员文章站 2024-03-20 20:27:16
...
#include<iostream>
using namespace std;
#include<cstring>
char oriL[5];
char light[5];
char result[5];

int GetBit(char c, int i) {
	return (c >> i) & 1;
}
void SetBit(char &c, int i, int v) {
	if (v) {
		c |= (1 << i);
	}
	else
		c &= ~(1 << i);
}
void Filp(char &c, int i) {
	c^= (1 << i);
}
void Output(int t, char result[]) {
	cout << "PUZZLE" << t << endl;
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 6; j++) {
			cout << GetBit(result[i], j);
			if (j < 5) cout << " ";
		}
		cout << endl;
	}
}
int main() {
	int T;
	cin >> T;
	for (int t = 1; t <= T; t++) {
		for(int i=0;i<5;i++)
		for (int j = 0; j < 6; j++) {
			int s;
			cin >> s;
			SetBit(oriL[i], j, s);
		}
		for (int n = 0; n < 64; n++) {
			int switchs = n;
			memcpy(light, oriL, sizeof(oriL));
			for (int i = 0; i < 5; i++) {
				result[i] = switchs;
				for (int j = 0; j < 6; j++) {
					if (GetBit(switchs, j)) {
						if (j > 0) Filp(light[i], j-1);
						Filp(light[i], j);
						if (j < 5) Filp(light[i], j + 1);
					}
				}
				if (i < 4) light[i + 1] ^= switchs;
				switchs = light[i];
			}
			if (light[4] == 0) {
				Output(t, result);
					break;
			}
	}
	}
	return 0;
}