• codeforces1293C


    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×n rectangle grid. NEKO's task is to lead a Nekomimi girl from cell (1,1) to the gate at (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 q such moments: the i-th moment toggles the state of cell (ri,ci) (either from ground to lava or vice versa).
    
    Knowing this, NEKO wonders, after each of the q moments, whether it is still possible to move from cell (1,1) to cell (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?

    题意:有一个2*n的田字格想要从(1,1)走到(2,n),但是中间会不定时有一些变故,这个变故可能是你某一个格子不能走了,也可能是原来不可以走的一个格子可以走了,问每一次变故之后可不可以到达目的地。

    对于一个原本没有任何障碍的格子,当有一个障碍的时候我们可以绕过他,假如格子(1,x)不通行了,那么我们可以从(1,x-1)走到(2,x-1)然后(2,x),(2,x+1),就绕过这个障碍格子了,但是什么时候绕不过呐?很显然当(2,x-1),(2,x),(2,x+1)任意一个也不能走的时候就不通行了。所以当一个格子不能通行的时候他可能对于最终结果没有影响也可能产生三个不能走的结果——取决于他不同行的三个邻居。我们用cnt记录当前有几个组合是会阻断到目的地的路的,当cnt为0的时候,这个变故之后就是可以通行的。

     1 #include<iostream>
     2 #include<cstdio>
     3 using namespace std;
     4 const int maxn=1e5+5;
     5 int n,q;
     6 int a[3][maxn];
     7 int x,y;
     8 int cnt; 
     9 int check()
    10 {
    11     int ans=0;
    12     int flag=-1; 
    13     if(a[x][y])flag=1;
    14     if(x==1)
    15     {
    16         if(a[2][y-1])ans++;
    17         if(a[2][y])ans++;
    18         if(a[2][y+1])ans++;
    19     }else
    20     {
    21         if(a[1][y-1])ans++;
    22         if(a[1][y])ans++;
    23         if(a[1][y+1])ans++;
    24     }
    25     return flag*ans;
    26 }
    27 int main()
    28 {
    29     scanf("%d%d",&n,&q);
    30     while(q--)
    31     {
    32         scanf("%d%d",&x,&y);
    33         a[x][y]=!a[x][y];
    34         cnt+=check();
    35         if(cnt>0)printf("No
    ");
    36         else printf("Yes
    ");
    37     }
    38     return 0;
    39 }

      

  • 相关阅读:
    致虚极守静笃
    DNS 透明代理
    Java“禁止”泛型数组
    Java和C#语法对比
    JVM 内存区域 (运行时数据区域)
    Java8 使用
    G1收集器的收集原理
    BZOJ 2222: [Cqoi2006]猜数游戏【神奇的做法,傻逼题,猜结论】
    数据结构之网络流入门(Network Flow)简单小节
    BZOJ 1257: [CQOI2007]余数之和sum【神奇的做法,思维题】
  • 原文地址:https://www.cnblogs.com/yuelian/p/12574352.html
Copyright © 2020-2023  润新知