日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2023/12/31 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #168 (Div. 2)---A. Lights Out 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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




題目大意:現(xiàn)有3*3個(gè)開(kāi)關(guān),初始全為開(kāi)著。切換(開(kāi)變成關(guān),關(guān)變成開(kāi))每一個(gè)開(kāi)關(guān)的時(shí)候,與它直接相鄰的四個(gè)方向上的開(kāi)關(guān)也會(huì)切換,給出每一個(gè)開(kāi)關(guān)的切換次數(shù),問(wèn)最后各個(gè)開(kāi)關(guān)的狀態(tài)。


解題思路:我們僅僅須要推斷每一個(gè)開(kāi)關(guān)到最后總共被切換了多少次。直接推斷次數(shù)的奇偶就可以推斷某個(gè)開(kāi)關(guān)最后的狀態(tài)。直接遍歷每一個(gè)開(kāi)關(guān),可是假設(shè)直接在原來(lái)的開(kāi)關(guān)次數(shù)上加,會(huì)影響對(duì)后來(lái)的計(jì)算,所以,我們開(kāi)了兩個(gè)數(shù)組,A[][]和B[][]。A是輸入的每一個(gè)開(kāi)關(guān)的切換次數(shù),B是最后每一個(gè)開(kāi)關(guān)切換的總次數(shù)。最后在掃一遍B就可以,若B[i][j]是奇數(shù),則狀態(tài)為0(關(guān)),否則狀態(tài)為1(開(kāi))。





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


總結(jié)

以上是生活随笔為你收集整理的Codeforces Round #168 (Div. 2)---A. Lights Out的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。