[CodeForces] [思维] NEKO's Maze Game

This question is send him to share the title.

topic

Topic Link

Comment

Thinking questions, would like to see is extremely simple.

First, consider the circumstances under which the road will be sealed:

There are three cases.

So obviously we do not need each time from 1 to n there is no way to find it again, each change of status on a plaid check the status of another column three grid can be. And then stored in a variable ans enough about the total number of blocked road grid. ans is zero YES, otherwise NO.

Code

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=100000+5;
 4 bool a[maxn],b[maxn];
 5 int n,q;
 6 int main(){
 7     ios::sync_with_stdio(false);
 8     cin>>n>>q;
 9     int ans=0;
10     for(int i=1;i<=q;i++){
11         int x,y;
12         cin>>x>>y;
13         if(x==1){
14             if(a[y]){
15                 a[y]=0;
16                 if(b[y]) ans--;
17                 if(b[y+1]) ans--;
18                 if(b[y-1]) ans--;
19             }
20             else{
21                 a[y]=1;
22                 if(b[y]) ans++;
23                 if(b[y+1]) ans++;
24                 if(b[y-1]) ans++;
25             }
26         }
27         else{
28             if(b[y]){
29                 b[y]=0;
30                 if(a[y]) ans--;
31                 if(a[y+1]) ans--;
32                 if(a[y-1]) ans--;
33             }
34             else{
35                 b[y]=1;
36                 if(a[y]) ans++;
37                 if(a[y+1]) ans++;
38                 if(a[y-1]) ans++;
39             }
40         }
41         if(ans) cout<<"No"<<endl;
42         else cout<<"Yes"<<endl;
43     }
44     return 0;
45 }
View Code

(I was back playing table when the entry-feeling)

 

Fortunately, even holy, songs to chant blog.

Guess you like

Origin www.cnblogs.com/DarthVictor/p/12630426.html