Lights Out
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 0x7fffffffint a[4][4], b[4][4];int main()
{#ifdef sxkfreopen("in.txt","r",stdin);#endifint 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)

    这场比赛因为坐火车没有做,到学校了, 坑爹的学校晚上要熄灯. 还有一些原因以后cf就不能及时的做了. 但是每场我肯定都不会落下. 这场b题严重坑, 被坑了1个半小时,关键还是自己的心理在作祟,思维不行 ...

  2. Codeforces Round #168 (Div. 2)D. Zero Tree(DP,中等难度)

    D. Zero Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  3. Codeforces Round #797 (Div. 3)无F

    Codeforces Round #797 (Div. 3)无F 这打的也太屎了,白天把G补了才知道简单的很,但f还是没头绪呜呜呜 Problem - A - Codeforces Given the ...

  4. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  5. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  6. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  7. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  8. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  9. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

最新文章

  1. 以简求快--java快速开发框架
  2. hdu-2553 N皇后问题(深搜 + 状态压缩)
  3. 每天一道LeetCode-----将m × n矩阵按照顺时针螺旋顺序转化成一维数组
  4. spring 调用python_Spring http服务远程调用实现过程解析
  5. JBoss Fuse 6.2发布–指导如何快速尝试
  6. fullgc频繁的原因_系统运行缓慢,CPU 100%,Full GC次数过多,这一招帮你全搞定
  7. final 数组 java_Java Final数组列表
  8. jquery.cookie.js使用
  9. Mysql学习总结(79)——MySQL常用函数总结
  10. Leetcode 刷题笔记(一) —— 数组类型解题方法一:二分法
  11. 清华大学计算机专业高中选课系统,【清华大学计算机实验教学中心】_清华大学计算机实验教学中心...
  12. 合泰单片机驱动步进电机程序
  13. html遮罩层样式,遮罩层样式
  14. 字体样式font-style的介绍
  15. resultFul请求案例
  16. 如何运营高效的社群?
  17. 【AI公司酷05期】美宅科技:独创人工智能室内设计引擎,帮你3秒搞定装修方案,要用AI赋能家居新零售
  18. 工作遇坑-Cannot allocate memory问题解决方法
  19. 关于订单功能的处理和分析
  20. DTOJ #3702. 月读(tsukuyomi)

热门文章

  1. jquery mobile资源
  2. Android深入浅出系列之实例应用—弹出消息Toast对象的使用自定义方式(二)
  3. ping命令时常碰到的问题
  4. Flask的session使用
  5. 2017CCPC 杭州 J. Master of GCD【差分标记/线段树/GCD】
  6. VMware 安装ubuntu 18.04遇到的问题
  7. 第七次团队作业——日不落战队
  8. 关于导航按钮在其他尺寸下显示问题
  9. 收集的一些jQuery (我平常用的少的,但确实挺有效果的)
  10. 1069: [SCOI2007]最大土地面积 - BZOJ