Codeforces Round #168 (Div. 2)-A. Lights Out_html/css_WEB-ITnose
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 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 <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 sxk freopen("in.txt","r",stdin); #endif int n; for(int i=0; i 0) b[i-1][j] += a[i][j]; if(i 0) b[i][j-1] += a[i][j]; if(j <br> <br> <p></p> <p><br> </p> </time.h></stdlib.h></math.h></string></map></set></queue></vector></algorithm></iostream></string.h></stdio.h>

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

本文讨论了HTML&lt; Progress&gt;元素,其目的,样式和与&lt; meter&gt;元素。主要重点是使用&lt; progress&gt;为了完成任务和LT;仪表&gt;对于stati

本文讨论了html&lt; datalist&gt;元素,通过提供自动完整建议,改善用户体验并减少错误来增强表格。Character计数:159

本文讨论了HTML&lt; meter&gt;元素,用于在一个范围内显示标量或分数值及其在Web开发中的常见应用。它区分了&lt; meter&gt;从&lt; progress&gt;和前

本文讨论了视口元标签,这对于移动设备上的响应式Web设计至关重要。它解释了如何正确使用确保最佳的内容缩放和用户交互,而滥用可能会导致设计和可访问性问题。

本文讨论了使用HTML5表单验证属性,例如必需的,图案,最小,最大和长度限制,以直接在浏览器中验证用户输入。

本文解释了HTML5&lt; time&gt;语义日期/时间表示的元素。 它强调了DateTime属性对机器可读性(ISO 8601格式)的重要性,并在人类可读文本旁边,增强Accessibilit

本文讨论了&lt; iframe&gt;将外部内容嵌入网页,其常见用途,安全风险以及诸如对象标签和API等替代方案的目的。
