• NEKO's Maze Game 思维


    NEKO#ΦωΦ has just got a new maze game on her PC!

    The game's main puzzle is a maze, in the forms of a 2×n2×n rectangle grid. NEKO's task is to lead a Nekomimi girl from cell (1,1)(1,1) to the gate at (2,n)(2,n) and escape the maze. The girl can only move between cells sharing a common side.

    However, at some moments during the game, some cells may change their state: either from normal ground to lava (which forbids movement into that cell), or vice versa (which makes that cell passable again). Initially all cells are of the ground type.

    After hours of streaming, NEKO finally figured out there are only qq such moments: the ii-th moment toggles the state of cell (ri,ci)(ri,ci) (either from ground to lava or vice versa).

    Knowing this, NEKO wonders, after each of the qq moments, whether it is still possible to move from cell (1,1)(1,1) to cell (2,n)(2,n) without going through any lava cells.

    Although NEKO is a great streamer and gamer, she still can't get through quizzes and problems requiring large amount of Brain Power. Can you help her?

    Input

    The first line contains integers nn, qq (2n1052≤n≤105, 1q1051≤q≤105).

    The ii-th of qq following lines contains two integers riri, cici (1ri21≤ri≤2, 1cin1≤ci≤n), denoting the coordinates of the cell to be flipped at the ii-th moment.

    It is guaranteed that cells (1,1)(1,1) and (2,n)(2,n) never appear in the query list.

    Output

    For each moment, if it is possible to travel from cell (1,1)(1,1) to cell (2,n)(2,n), print "Yes", otherwise print "No". There should be exactly qq answers, one after every update.

    You can print the words in any case (either lowercase, uppercase or mixed).

    Example

    Input
    5 5
    2 3
    1 4
    2 4
    2 3
    1 4
    
    Output
    Yes
    No
    No
    No
    Yes
    

    Note

    We'll crack down the example test here:

    • After the first query, the girl still able to reach the goal. One of the shortest path ways should be: (1,1)(1,2)(1,3)(1,4)(1,5)(2,5)(1,1)→(1,2)→(1,3)→(1,4)→(1,5)→(2,5).
    • After the second query, it's impossible to move to the goal, since the farthest cell she could reach is (1,3)(1,3).
    • After the fourth query, the (2,3)(2,3) is not blocked, but now all the 44-th column is blocked, so she still can't reach the goal.
    • After the fifth query, the column barrier has been lifted, thus she can go to the final goal again.

    题意:给定n表示有2*n个格子,询问q次,每次将一个格子变换状态(地面变成熔岩,反之亦然),输出能否从(1,1)到(2,n)

    分析:

    如果将(1,4)变成熔岩,

    如果画蓝线的有一个是熔岩,就无法经过。

    然后我们需要计算障碍的数量,根据每次输入的格子的位置,判断和它相邻的三个位置是否有熔岩,如果该格子变换后是熔岩,对于相邻三个位置的每个位置,如果是熔岩的话就ans++。反之ans--。

    每次询问如果ans是0的话说明没有障碍,输出Yes,否则输出No。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 1e5 + 5;
     4 int q, n, m, num[3][maxn], last, k;
     5 int main(){
     6     scanf("%d%d", &n, &q);
     7     int ans = 0;
     8     for (int i = 1; i <= q; i++){
     9         int x, y;
    10         scanf("%d%d", &x, &y);
    11         if (num[x][y] == 0){
    12             num[x][y] = 1;
    13             int xx = (x % 2) + 1;
    14             if (num[xx][y-1] && y - 1 >= 1) ans++;
    15             if (num[xx][y]) ans++;
    16             if (num[xx][y+1] && y + 1 <= n) ans++;
    17         }
    18         else {
    19             num[x][y] = 0;
    20             int xx = (x % 2) + 1;
    21             if (num[xx][y-1] && y - 1 >= 1 ) ans--;
    22             if (num[xx][y]) ans--;
    23             if (num[xx][y+1] && y + 1 <= n) ans--;
    24         }
    25         if (!ans) printf("Yes
    ");
    26         else printf("No
    ");
    27     }
    28     return 0;
    29 }
    View Code
  • 相关阅读:
    XML 读取器和编写器从URL读取XML
    8月8号 星期五
    080808 晴
    080805
    雨景
    用photoshop批量修改照片(待修改)
    8月7日 晴
    五不
    Android 画渐变的背景
    iOS开发的一些基础知识
  • 原文地址:https://www.cnblogs.com/ghosh/p/12637927.html
Copyright © 2020-2023  润新知