Codeforces Round #168 (Div. 2)---A. Lights Out
2 seconds
256 megabytes
standard input
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.
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.
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".
1 0 0
0 0 0
0 0 1
001
010
100
1 0 1
8 8 8
2 0 3
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的更多相关文章
- Codeforces Round #168 (Div. 2)
A. Lights Out 模拟. B. Convex Shape 考虑每个黑色格子作为起点,拐弯次数为0的格子构成十字形,拐弯1次的则是从这些格子出发直走达到的点,显然需要遍历到所有黑色黑色格子. ...
- Codeforces Round #168 (Div. 1 + Div. 2)
A. Lights Out 模拟. B. Convex Shape 考虑每个黑色格子作为起点,拐弯次数为0的格子构成十字形,拐弯1次的则是从这些格子出发直走达到的点,显然需要遍历到所有黑色黑色格子. ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- 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 ...
- 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 ...
随机推荐
- hdoj--1258--Sum It Up(dfs)
Sum It Up Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- typeof、instanceof、hasOwnProperty()、isPrototypeOf()
typeof 操作符 instanceof 操作符 hasOwnProperty()方法 isPrototypeOf()方法 1.typeof 用于获取变量的类型,一般只返回以下几个值:string, ...
- 什么是Ajax和JSON,他们的优缺点?
ajax的概念:ajax是一种通过后台与服务器进行少量的数据交换,实现页面异步更新 是一种创建交互式网页应用的网页开发技术. json的概念:json是一种轻量级的数据交换格式,具有良好的可读和便于快 ...
- BZOJ 3065 替罪羊树+动态开节点线段树
思路: RT 可以看VFK的题解 我写了半天拍了半天... 不过是$nlog^2n$的 要写垃圾回收的 线段树 如果某个节点的sum是0 也可以free掉 //By SiriusRen #inclu ...
- BZOJ 1537 cdq分治
思路: 我只是想写一下cdq-- 二维偏序 一维排序 一维cdq分治 (我忘了归并排序怎么写了,,,) 写了个sort- 复杂度是O(nlog^2n) //By SiriusRen #include ...
- Hadoop MapReduce编程 API入门系列之wordcount版本5(九)
这篇博客,给大家,体会不一样的版本编程. 代码 package zhouls.bigdata.myMapReduce.wordcount1; import java.io.IOException; i ...
- C#调用SMS短信接口,轻松搞定发送短信的任务。。。。
首先我们需要去这里http://sms.webchinese.cn/申请一个账号和短信接口秘钥,在该网址下有许多语言的demo介绍,下面我主要为大家贴一个C#中的Helper类: using Syst ...
- python3遍历选中文件夹下的文件【GUI编程】
功能介绍 如标题 使用截图 1.第一步:运行python程序 2.第二步:点击按钮选中文件夹 3.运行结束: 1. 显示选中文件夹路径 2. 遍历打印文件夹内文件 代码 import os #程序功能 ...
- String,StringBuffer,StringBuilder效率优先关系说明
String,StringBuffer,StringBuilder效率优先关系说明: public class StringBufferWithStringBuilder { public stati ...
- OnLineML一:关于Jubatus 的简介...
一:简介:原文链接:jubat.us/en/ xuwenq.iteye.com/blog/1702746 Jubatus http://jubat.us/en/overview.html 是一个面向 ...