CodeForces 1292A NEKO's Maze Game(思维)
1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <string> 5 #include <math.h> 6 #include <algorithm> 7 #include <vector> 8 #include <stack> 9 #include <queue> 10 #include <set> 11 #include <map> 12 #include <sstream> 13 #include <ctime> 14 const int INF=0x3f3f3f3f; 15 typedef long long LL; 16 const int mod=1e9+7; 17 const LL MOD=1e9+7; 18 const double PI = acos(-1); 19 const double eps =1e-8; 20 #define Bug cout<<"---------------------"<<endl 21 const int maxn=1e5+10; 22 using namespace std; 23 24 map<pair<int,int>,int> mp; 25 26 int main() 27 { 28 #ifdef DEBUG 29 freopen("sample.txt","r",stdin); 30 #endif 31 // ios_base::sync_with_stdio(false); 32 // cin.tie(NULL); 33 34 35 int n,q; 36 scanf("%d %d",&n,&q); 37 int lim=0; 38 for(int i=1;i<=q;i++) 39 { 40 int a,b; 41 scanf("%d %d",&a,&b); 42 if(!mp[make_pair(a,b)]) 43 { 44 mp[make_pair(a,b)]++; 45 if(a==1) 46 { 47 if(mp[make_pair(a+1,b-1)]) lim++; 48 if(mp[make_pair(a+1,b)]) lim++; 49 if(mp[make_pair(a+1,b+1)]) lim++; 50 } 51 else if(a==2) 52 { 53 if(mp[make_pair(a-1,b-1)]) lim++; 54 if(mp[make_pair(a-1,b)]) lim++; 55 if(mp[make_pair(a-1,b+1)]) lim++; 56 } 57 } 58 else 59 { 60 mp[make_pair(a,b)]--; 61 if(a==1) 62 { 63 if(mp[make_pair(a+1,b-1)]) lim--; 64 if(mp[make_pair(a+1,b)]) lim--; 65 if(mp[make_pair(a+1,b+1)]) lim--; 66 } 67 else if(a==2) 68 { 69 if(mp[make_pair(a-1,b-1)]) lim--; 70 if(mp[make_pair(a-1,b)]) lim--; 71 if(mp[make_pair(a-1,b+1)]) lim--; 72 } 73 } 74 if(lim) printf("NO\n"); 75 else printf("YES\n"); 76 } 77 78 return 0; 79 } 80
-