poj 1222 Extended lights out (emulator)

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

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;
}













评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值