zoukankan      html  css  js  c++  java
  • 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 }

      

  • 相关阅读:
    安装oh-my-zsh失败,可按以下方式安装
    aria2 for mac
    java抛出异常后,后续代码是否可继续执行
    mac多线程下载神器
    Oracle--大数据迁移--sqlldr技术的应用
    Windows版 GCC编译器安装和使用--MinGW
    Visual Studio 2015 安装与注册
    android studio 3.6 环境搭建(安装步骤)
    IDEA--主题样式设置
    数据--innercode--的处理
  • 原文地址:https://www.cnblogs.com/yuelian/p/12574352.html
Copyright © 2011-2022 走看看