博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #168 (Div. 2)---A. Lights Out
阅读量:6197 次
发布时间:2019-06-21

本文共 2205 字,大约阅读时间需要 7 分钟。

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Lenny is playing a game on a 3 × 3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.

Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.

Input

The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The j-th number in the i-th row is the number of times the j-th light of the i-th row of the grid is pressed.

Output

Print three lines, each containing three characters. The j-th character of the i-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".

Sample test(s)
input
1 0 00 0 00 0 1
output
001010100
input
1 0 18 8 82 0 3
output
010011100

题目大意:现有3*3个开关,初始全为开着。切换(开变成关,关变成开)每一个开关的时候,与它直接相邻的四个方向上的开关也会切换,给出每一个开关的切换次数,问最后各个开关的状态。

解题思路:我们仅仅须要推断每一个开关到最后总共被切换了多少次。直接推断次数的奇偶就可以推断某个开关最后的状态。直接遍历每一个开关,可是假设直接在原来的开关次数上加,会影响对后来的计算,所以,我们开了两个数组,A[][]和B[][]。A是输入的每一个开关的切换次数,B是最后每一个开关切换的总次数。最后在扫一遍B就可以,若B[i][j]是奇数,则状态为0(关),否则状态为1(开)。

AC代码:

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define INF 0x7fffffffint a[4][4], b[4][4];int main(){ #ifdef sxk freopen("in.txt","r",stdin); #endif int n; for(int i=0; i<3; i++) for(int j=0; j<3; j++) scanf("%d", &a[i][j]); memset(b,0,sizeof(b)); for(int i=0; i<3; i++) for(int j=0; j<3; j++){ if(a[i][j]){ b[i][j] += a[i][j]; if(i > 0) b[i-1][j] += a[i][j]; if(i < 2) b[i+1][j] += a[i][j]; if(j > 0) b[i][j-1] += a[i][j]; if(j < 2) b[i][j+1] += a[i][j]; } } for(int i=0; i<3; i++){ for(int j=0; j<3; j++){ printf("%d", b[i][j]&1^1); } printf("\n"); } return 0;}

转载地址:http://gvjca.baihongyu.com/

你可能感兴趣的文章
IntelliJ IDEA推荐插件
查看>>
RandomStringUtils RandomUtils
查看>>
Notification 浏览器的消息推送
查看>>
[转载]你所不了解的DevOps
查看>>
关于双十二崩盘的一些思考
查看>>
centos7 开启端口防火墙配置(如开启3306或者80端口)
查看>>
async/await使用深入详解
查看>>
uemacs快捷键
查看>>
ASP.NET编程模型:RegisterStartupScript向页面注册脚本
查看>>
LPC21O3第一课:第一个实验,LED灯闪烁及ADS1.2的初步使用
查看>>
matlab练习程序(共生矩阵)
查看>>
BizTalk Server 2006 R3 is Announced
查看>>
[译]C# Socket连接请求超时机制
查看>>
fileAs访问拒绝and net后台打开服务器端文件和关闭服务器端文件
查看>>
POJ 3020 Antenna Placement
查看>>
POJ 1486 Sorting Slides (KM)
查看>>
解决 NDP40-KB2468871不能安装
查看>>
《数据结构与算法分析》学习笔记(三)——链表ADT
查看>>
通信原理实践(三)——FM调制
查看>>
mysql 学习总结
查看>>