This is an emulator question. Just try the answer so many times and you can solve it. However there are some tips as follow.
(1) If you want to turn off all lights on the first row, you should press the button on the second row to affect it and so on.
(2) the status of lights on the 5th row depend on the initial status of the first row, so just try to change the status of all lights on the first row as much as possible. The maximum try is 2^6 = 64;
#include<stdio.h>
#include<iostream>
#include<string.h>
int press[7][8], puzzle[7][8];
void emulator();
bool guess();
int main(){
int n, sum = 0;
scanf("%d", &n);
while(n--){
memset(puzzle, 0, sizeof(puzzle));
memset(press, 0, sizeof(press));
for(int i = 1; i <= 5; i++){
for(int j = 1; j <= 6; j++){
scanf("%d",&puzzle[i][j]);
}
}
emulator();
printf("PUZZLE #%d\n", ++sum);
for(int i = 1; i <= 5; i++){
for(int j = 1; j <=6; j++){
if(j == 6){
printf("%d", press[i][j]);
}else{
printf("%d ", press[i][j]);
}
}
printf("\n");
}
}
}
void emulator(){ // emulate all the possible status of all lights on the fist row
for(int i = 1; i <= 64; i++){
int pos = 1;
press[1][pos]++;
while(press[1][pos] > 1){
press[1][pos++] = 0;
press[1][pos]++;
}
press[1][7] = 0;
if(guess() == true){
break;
}
}
}
bool guess(){ // judge whether it can make all the lights on the map turn off. Pay much more attention on the lights of last row
for(int i = 2;i <= 5; i++){
for(int j = 1;j <= 6; j++){
press[i][j] = (press[i-1][j] + press[i-2][j] + press[i-1][j-1] + press[i-1][j+1] + puzzle[i-1][j]) % 2;
}
}
int pos = 5;
for(int j = 1; j <= 6; j++){
if(press[pos][j] != (press[pos-1][j] + press[pos][j-1] + press[pos][j+1] + puzzle[pos][j]) % 2){
return false;
}
}
return true;
}

本文深入探讨了Unity3D和Unreal Engine两款顶级游戏引擎的使用技巧,从基础概念到高级特性,为游戏开发者提供全面的指导。包括动画制作、物理引擎应用、渲染优化等关键内容,旨在帮助开发者提高游戏开发效率和质量。

被折叠的 条评论
为什么被折叠?



