zoukankan      html  css  js  c++  java
  • Codeforces Round #614 (Div. 2)C 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×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 qq such moments: the ii -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 qq 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?

    Input

    The first line contains integers n , q (2≤n≤1e5 , 1≤q≤1e5 ).

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

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

    Output

    For each moment, if it is possible to travel from cell (1,1) to cell (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

    Copy

    5 5 2 3 1 4 2 4 2 3 1 4 Output

    Copy

    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.

    大致题意

    题意:给定一个2*n的空间,每次翻转一个空间,(整个空间初始都是可以通过的,翻转一次即不可通过,两次即可以通过)每当进行一次翻转,判断此时是否可以从空间(1,1)到达空间(2,n)。

    注意

    这道题因为只有两行,所以当翻转其中一个空间之后,我们只需判断这个空间位置的不同行同列和其相邻位置是否可以通过即可

    最后看一下代码

    #include <bits/stdc++.h>
    using namespace std;
    const int maxn = 1e5 + 10;
    int vis[2][maxn];
    int main(){
        ios::sync_with_stdio(0);
        int n,q,s,t,sum=0;
        cin>>n>>q;
        while (q--){
            cin>>s>>t;
            s--;
            vis[s][t]^=1;
            
            if (vis[s][t]==1){//必须分开进行判断,才能保证之前的翻转造成的不通路在翻转成可通过之后形成通路。
                if (vis[s^1][t+1]==1)
                    sum++;
                    if(vis[s^1][t]==1)
                    sum++;
                    if(vis[s^1][t-1]==1)
                    sum++;
            }
            else{
                if (vis[s^1][t+1]==1)
                    sum--;
                    if(vis[s^1][t]==1)
                    sum--;
                    if(vis[s^1][t-1]==1)
                    sum--;
                
            }
            if (sum== 0)
                cout << "Yes"<<endl;
            else
                cout << "No"<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Tomcat 7 自动加载类及检测文件变动原理
    ElasticSearch查询
    ElasticSearch集群的基本原理
    ElasticSearch基础
    hbase时间不同步问题引起的bug
    IDEA运行异常java.lang.NoClassDefFoundError: org/apache/spark/api/java/function/Function
    spark任务提交之SparkLauncher
    spark调优(二)-Apache Spark 内存管理详解
    spark调优(一)-开发调优,数据倾斜,shuffle调优
    spark内核源码深度剖析(1)--Spark内核架构深度剖析
  • 原文地址:https://www.cnblogs.com/Vocanda/p/12638416.html
Copyright © 2011-2022 走看看