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

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

A. 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
1 #include 
2 #include
3 #include
4 5 using namespace std; 6 7 int map[4][4], cnt[4][4]; 8 const int pos[4][2] = {
{-1, 0}, {
1, 0}, {
0, 1}, {
0, -1}}; 9 10 bool Judge(int i, int j)11 {12 return (i < 3 && i >= 0 && j < 3 && j >= 0);13 }14 15 void Press(int i, int j)16 {17 cnt[i][j] += map[i][j];18 for(int k = 0; k < 4; k++)19 {20 int ii = i + pos[k][0];21 int jj = j + pos[k][1];22 if(Judge(ii, jj))23 cnt[ii][jj] += map[i][j];24 }25 }26 27 int main()28 {29 while(scanf("%d", &map[0][0]) != EOF)30 {31 memset(cnt, 0, sizeof(cnt));32 Press(0, 0);33 for(int i = 0; i < 3; i++)34 {35 for(int j = 0; j < 3; j++)36 {37 if(!i && !j) continue;38 scanf("%d", &map[i][j]);39 Press(i, j);40 }41 }42 for(int i = 0; i < 3; i++)43 {44 for(int j = 0; j < 3; j++)45 printf("%d", 1 - (cnt[i][j] & 1));46 puts("");47 }48 }49 return 0;50 }

 

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

你可能感兴趣的文章
转贴:Ms Sql Server 2008 集成 SP1的方法!!!
查看>>
Memcache监控工具 -- memcache-top
查看>>
3-9 读写缓存流 ——BufferedStream类
查看>>
linux head
查看>>
Oracle osw监控工具的使用示例
查看>>
在Spring中整合JUnit单元测试
查看>>
Namenode双机热备之Pacemaker
查看>>
Xcode调试断点不停止解决方案!
查看>>
CentOS6.6+Puppet3.7.4分布式部署Nagios监控系统
查看>>
SQL Server 2008 存储结构之DCM、BCM
查看>>
asp.net2005里给控件重命名,提示“目录名无效”怎么解决
查看>>
Redis源码解析--Replication
查看>>
Java的多进程运行模式分析
查看>>
百度面试题:求绝对值最小的数
查看>>
敏捷个人手机应用:如何使用时中法目标
查看>>
Android 解决ListView 和 ScrollView 共存冲突的问题
查看>>
利用Power Designer反向数据库结构
查看>>
在ISA 2006企业版环境下配置存储服务器(CSS)
查看>>
使用Seam-gen生成基础项目骨架
查看>>
RHCE学习<13>RHCS集群(RHCS+GFS2+ISCSI)
查看>>