zoukankan      html  css  js  c++  java
  • Codeforces Round #168 (Div. 2) A. Lights Out(模拟)

    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 <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     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 }
  • 相关阅读:
    jQuery Validate 插件
    jquery.validate.js校验select2解决方案,Jquery插件select2校验解决方案
    各大浏览器CSS Hack收集
    Jquery方法load之后导致js失效解决方法
    list-style无颜色问题解决,list-style-type无颜色解决
    Css实现透明效果,兼容IE8
    jdk配置及maven配置
    兼容IE浏览器的placeholder【超不错】
    laydate兼容bootstrap
    section和article元素
  • 原文地址:https://www.cnblogs.com/cszlg/p/2921931.html
Copyright © 2011-2022 走看看