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 0
0 0 0
0 0 1
output
001
010
100
input
1 0 1
8 8 8
2 0 3
output
010
011
100

题目大意:现有3*3个开关。初始全为开着。

切换(开变成关。关变成开)每一个开关的时候,与它直接相邻的四个方向上的开关也会切换,给出每一个开关的切换次数。问最后各个开关的状态。

解题思路:我们仅仅须要推断每一个开关到最后总共被切换了多少次,直接推断次数的奇偶就可以推断某个开关最后的状态。

直接遍历每一个开关。可是假设直接在原来的开关次数上加,会影响对后来的计算。所以,我们开了两个数组,A[][]和B[][],A是输入的每一个开关的切换次数,B是最后每一个开关切换的总次数。最后在扫一遍B就可以。若B[i][j]是奇数,则状态为0(关),否则状态为1(开)。

AC代码:

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define INF 0x7fffffff int 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;
}

Codeforces Round #168 (Div. 2)---A. Lights Out的更多相关文章

  1. Codeforces Round #168 (Div. 2)

    A. Lights Out 模拟. B. Convex Shape 考虑每个黑色格子作为起点,拐弯次数为0的格子构成十字形,拐弯1次的则是从这些格子出发直走达到的点,显然需要遍历到所有黑色黑色格子. ...

  2. Codeforces Round #168 (Div. 1 + Div. 2)

    A. Lights Out 模拟. B. Convex Shape 考虑每个黑色格子作为起点,拐弯次数为0的格子构成十字形,拐弯1次的则是从这些格子出发直走达到的点,显然需要遍历到所有黑色黑色格子. ...

  3. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  4. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  5. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  6. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  7. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  8. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  9. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

随机推荐

  1. ijkplayer详解AAA

    https://www.jianshu.com/p/c5d972ab0309 https://www.android-arsenal.com/details/1/530 https://stackov ...

  2. [ASPX] DotLiquid-Asp.net模板引擎

    以前用过一段时间的PHP,感觉非常不错,其中最让我难忘的就是Smarty模板引擎,当时就微微地想Asp.net里有没有像这样的模板引擎呢?不过由于之后的工作内容都用不到,或者说没有想到用模板,这想法也 ...

  3. jquery的this和$(this)

    1.JQuery this和$(this)的区别 相信很多刚接触JQuery的人,很多都会对$(this)和this的区别模糊不清,那么这两者有什么区别呢? 首先来看看JQuery中的  $()  这 ...

  4. Hadoop MapReduce编程 API入门系列之挖掘气象数据版本2(十)

    下面,是版本1. Hadoop MapReduce编程 API入门系列之挖掘气象数据版本1(一) 这篇博文,包括了,实际生产开发非常重要的,单元测试和调试代码.这里不多赘述,直接送上代码. MRUni ...

  5. 判断输入的值是否为Double

    using System; using System.Collections.Generic; using System.Text; namespace TDRFactory { public cla ...

  6. 第7章 性能和可靠性模式 Load-Balanced Cluster(负载平衡群集)

    上下文 您已经决定在设计或修改基础结构层时使用群集,以便在能够适应不断变化的要求的同时保持良好的性能. 问题 在保持可接受的性能级别的同时,如何设计一个可适应负载变化的.可伸缩的基础结构层? 影响因素 ...

  7. Tomcat 报错 记录

    Resource is out of sync with the file system: 该错误为替换了image中的图片而没有进行更新,造成找不到该资源,进而保存,解决只要eclipse刷新一下F ...

  8. android黑科技系列——微信抢红包插件原理解析和开发实现

    一.前言 自从几年前微信添加抢红包的功能,微信的电商之旅算是正式开始正式火爆起来.但是作为Android开发者来说,我们在抢红包的同时意识到了很多问题,就是手动去抢红包的速度慢了,当然这些有很多原因导 ...

  9. Paint、Canvas.2

    1:使用Cavans画个简单图形 2:过程 2.1:绘制最外部的圆 /*** 初始化 paint */ Paint paint; paint = new Paint(); paint.setColor ...

  10. RAP开发入门-主题更换

    通过配置扩展点修改应用主题    ps:需要提前准备好主题(theme.css)文件   <!-- 注册主题扩展点 -->    <extension          point= ...