Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
#include<bits/stdc++.h> using namespace std; #define ll long long #define pi (4*atan(1.0)) #define eps 1e-14 const int N=4e5+100,M=4e6+10,inf=1e9+10,mod=1e9+7; const ll INF=1e18+10; char ch[10]; int main() { int T,cas=1; scanf("%d",&T); while(T--) { printf("Case #%d:\n",cas++); int st=200010,en=200010,f=0; int n; scanf("%d",&n); set<int>s; set<int>::iterator it; for(int i=1;i<=n;i++) { scanf("%s",ch); if(ch[0]==‘P‘) { if(ch[1]==‘U‘) { int x; scanf("%d",&x); if(x==0) s.insert(en); if(f) en--; else en++; } else { if(f) { if(!s.empty()) { it=s.begin(); if(*it<=en+1) s.erase(it); } en++; } else { if(!s.empty()) { it=s.end(); it--; if(*it>=en-1) s.erase(it); } en--; } } } else if(ch[0]==‘Q‘) { if(st==en) { printf("Invalid.\n"); } else if(s.empty()) { printf("%d\n",abs((en-st)%2)); } else if(f) { int p; it=s.end(); it--; p=*it; int ans=st-p; if(p>en+1)ans++; printf("%d\n",ans%2); } else { int p; it=s.begin(); p=*it; int ans=p-st; if(p<en-1)ans++; printf("%d\n",ans%2); } } else { if(f) { int temp=st; st=en+1; en=temp+1; f=0; } else { int temp=st; st=en-1; en=temp-1; f=1; } } } } return 0; }
HDU 5929 Basic Data Structure 模拟
原文:http://www.cnblogs.com/jhz033/p/5937204.html