NEKO's Maze Game-cf

  Question is intended: to give you a 2 × n matrix, starting in the upper left, the lower right end, can be moved into an adjacent cell of the grid of the present, you q time points, each point in time there is a change in state in the lattice , the state is divided into a grid to go and not go, so the grid are beginning to go, requiring the output of each point of time can not come to the end from the beginning.

 

  Ideas: for any grid, the set of its coordinates x, y, coordinates for the three other rows his 3-x, y-1, 3-x, y , and 3-x, y + 1 there is a can not go, the whole road was stuffed dead, they can not come to the end from the beginning. That is the whole matrix satisfy this relationship at any point, the whole road leads nowhere, so we count how many groups throughout the matrix of this relationship is set to num, for each time point, if it is to lift the seal grid, it will be it reduces the number of groups minus num, the grid is to make corresponding banned num plus, at each time point is not to determine what num 0 on the line.

 

  ac Code:

#include<iostream>
using namespace std;
const int maxn=1e5+10;
int n,q;
int vis[3][maxn];
int ans[maxn];//0可以,1不行
 
int check(int x,int y){
    int h=3-x;
    if(y==1){
        return vis[h][y]+vis[h][y+1];
    }
    else if(y==n){
        return vis[h][y-1]+vis[h][y];
    }
    else
        return vis[h][y-1]+vis[h][y]+vis[h][y+1];
} 
 
 
int main()
{
    cin>>n>>q;
    int x,y,num=0,now=0;
    for(int i=1;i<=q;i++){
        cin>>x>>y;
        if(vis[x][y]==0){
            num-=check(x,y);
        }
        else{
            num+=check(x,y);
        }
        if(num==0) ans[i]=0;
        else ans[i]=1;
        vis[x][y]^=1;
    }
    for(int i=1;i<=q;i++){
        if(ans[i]==0) cout<<"Yes\n";
        else cout<<"No\n";
    }
    return 0;
} 

Guess you like

Origin www.cnblogs.com/qq2210446939/p/12227230.html