Codeforces Round #168 (Div. 2)---A. Lights Out

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;
}



转载于:https://www.cnblogs.com/claireyuancy/p/6917649.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/400857.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【C#/VB.NET】 将PDF转为SVG/Image, SVG/Image转PDF

&#x1f680; 优质资源分享 &#x1f680; 学习路线指引&#xff08;点击解锁&#xff09;知识定位人群定位&#x1f9e1; Python实战微信订餐小程序 &#x1f9e1;进阶级本课程是python flask微信小程序的完美结合&#xff0c;从项目搭建到腾讯云部署上线&#xff0c;打造一…

hiho模拟面试题2 补提交卡 (贪心,枚举)

题目&#xff1a; 时间限制:2000ms单点时限:1000ms内存限制:256MB描写叙述 小Ho给自己定了一个雄伟的目标&#xff1a;连续100天每天坚持在hihoCoder上提交一个程序。100天过去了。小Ho查看自己的提交记录发现有N天由于贪玩忘记提交了。于是小Ho软磨硬泡、强忍着小Hi歧视的眼神…

libcurl上传文件

libcurl参数很多&#xff0c;一不小心就容易遇到问题。曾经就遇到过一个很蛋疼的问题&#xff1a;libcurl断点下载>> 这里主要汇总一下&#xff0c;libcurl上传的二种方式&#xff1a; 1、直接上传文件&#xff0c;类似form表单<input type”file” />&#xff0c;…

MSP430F5529 DriverLib 库函数学习笔记(二)GPIO

目录硬知识一、MSP430单片机端口概述二、通用IO端口输出特性三、端口P1和P21&#xff0e;输入寄存器PxIN2&#xff0e;输出寄存器PxOUT3&#xff0e;方向寄存器PxDIR4&#xff0e;上拉/下拉电阻使能寄存器PxREN5&#xff0e;输出驱动能力调节寄存器PxDS6&#xff0e;功能选择寄…

IOS项目中加入Google Admob SDK

错误1. Undefined symbols for architecture i386: "_OBJC_CLASS_$_ASIdentifierManager", referenced from: objc-class-ref in libGoogleAdMobAds.a(GADIdentifierUtilities.o) "_OBJC_CLASS_$_SKStoreProductViewController", referenced from: …

【RocketMQ】MQ消息发送

&#x1f680; 优质资源分享 &#x1f680; 学习路线指引&#xff08;点击解锁&#xff09;知识定位人群定位&#x1f9e1; Python实战微信订餐小程序 &#x1f9e1;进阶级本课程是python flask微信小程序的完美结合&#xff0c;从项目搭建到腾讯云部署上线&#xff0c;打造一…

MSP430F5529 DriverLib 库函数学习笔记(三)认识中断

目录一、硬知识中断的基本概念MSP430单片机中断源中断响应过程中断返回过程中断嵌套二、msp430f5529.h中所列的中断向量宏定义平台&#xff1a;Code Composer Studio 10.3.1 MSP430F5529 LaunchPad™ Development Kit (MSP‑EXP430F5529LP) 一、硬知识 中断的基本概念 中断…

推荐系统相关算法

摘要&#xff1a; 热门推荐 协同过滤算法 矩阵分解 基于内容的推荐&#xff08;文本&#xff0c;标签&#xff0c;特征/profile&#xff09; 基于图的算法 内容&#xff1a; 热门推荐&#xff1a; 热门推荐本质上是一个排行榜&#xff0c;可能会考虑到时间衰减&#xff0c;商品…

冒泡排序的简单理解

&#x1f680; 优质资源分享 &#x1f680; 学习路线指引&#xff08;点击解锁&#xff09;知识定位人群定位&#x1f9e1; Python实战微信订餐小程序 &#x1f9e1;进阶级本课程是python flask微信小程序的完美结合&#xff0c;从项目搭建到腾讯云部署上线&#xff0c;打造一…

微软职位内部推荐-Software Engineer II

微软近期Open的职位:Job Title: Software Engineer IIWork Location: Suzhou/Beijing, ChinaJob Description:Are you looking for a big challenge? Do you know why Big Data is the next frontier for innovation, competition and productivity? Come join us to build i…

司机和售票员问题 信号signal注册一例

#include <stdio.h> #include <stdlib.h> #include <signal.h>pid_t pid;void driver_handler(int signo) //司机的信号处理函数 {if (signo SIGUSR1)printf("Lets go!\n");if (signo SIGUSR2)printf("Stop the bus!\n");if (signo …

MSP430F5529 DriverLib 库函数学习笔记(四)UART通信

目录硬知识USCI通信模块USCI的UART模式1. USCI初始化和复位2. 异步通信字符格式3. 异步多机通信模式4. 自动波特率检测5. IrDA编码和解码6. 自动错误检测7. USCI接收使能8. USCI发送使能9. UART波特率的产生10. UART波特率的设置&#xff08;重要&#xff09;&#xff08;1&…

linux下编译安装MySQL5.6新版本

MySQL 5.5以上版本 与之前的版本安装出入有些区别&#xff1a; 下面是安装过程mysql5.6 下载地址&#xff1a;ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.6/一&#xff1a;卸载旧版本使用下面的命令检查是否安装有MySQL Serverrpm -qa | grep mysql有的话通过下面…

MSP430F5529 DriverLib 库函数学习笔记(四点五)printf打印输出

目录代码实现使相应工程支持打印浮点数实验结果平台&#xff1a;Code Composer Studio 10.3.1 MSP430F5529 LaunchPad™ Development Kit (MSP‑EXP430F5529LP)代码实现 重定向fputc(int ch, FILE *f)直接使用printf的方法只有字符串和%s打印正常&#xff0c;数字打印不出来…

Android学习第三天--事件监听器

事件监听器方式一&#xff1a; 匿名内部类&#xff0c;直接在组件上添加监听器&#xff1b;例子如下 button.setOnclickListener(new OnClickListener() {System.out.println("hahahh"); }); 监听方式二&#xff1a; 实现某个监听器的接口&#xff0c;然后在添加…

FileOutputSteam入门

FileOutputSteam 字节输入流 从控制台将字节保存到本地硬盘 package com.isoftstone.io; import java.io.FileOutputStream; import java.io.IOException; public class TestFileOutStream {public static void main(String[] args){FileOutputStream fos null;try{//1、创建文…

认识弹性盒子flex

&#x1f680; 优质资源分享 &#x1f680; 学习路线指引&#xff08;点击解锁&#xff09;知识定位人群定位&#x1f9e1; Python实战微信订餐小程序 &#x1f9e1;进阶级本课程是python flask微信小程序的完美结合&#xff0c;从项目搭建到腾讯云部署上线&#xff0c;打造一…

Objective-C 语法

吧Category使用场景&#xff1a; -类包含了很多个方法的实现&#xff0c;而这些方法需要不同的团队成员来实现。 -当你在使用基础类库中的类时&#xff0c;不想集成这些类&#xff0c;只想添加一些方法时。 -Category能访问原始类的实例变量&#xff0c;但是不能添加实例变量&a…

flag

mark, to remember

MSP430F5529 DriverLib 库函数学习笔记(五)定时器A

目录硬知识定时器A 16位定时器原理&#xff08;1&#xff09;时钟源选择和分频器&#xff08;2&#xff09;Timer_A工作模式&#xff08;3&#xff09;捕获/比较模块&#xff08;4&#xff09;Timer_A中断&#xff08;重要&#xff09;定时器A API (机翻)定时器A配置和控制的函…