让我自闭了两个星期的题 Hello xtCpc
在比赛的时候这题卡了我们队3个小时,最后还是没过,放掉的时候依然不舍,始终找不到错解,比赛结束后回来自闭了2个星期,回来知道题目的解题时和自己当初解题的时候思路时一样的,只不过自己没有冷静下来把思路理的条例有序,导致当时wa了9次,直接搞崩心态。做题得一步一步来,绝不能有半点糊涂!一旦有糊涂,就找不到bug了,bug就藏在阴暗的角落,思维的盲点。让你难受。这题,我可能会记很久很久吧。
ac代码:
#include<iostream> #include<cstring> #include<queue> #include<cstdio> using namespace std; int main() { int n; while(~scanf("%d",&n)) { char a; int ans=0,maxn=200010; queue<int> x; queue<int> t; queue<int> C; queue<int> p; queue<int> c; getchar(); for(int i=0;i<n;i++) { scanf("%c",&a); if(a=='x') x.push(i); else if(a=='t') t.push(i); else if(a=='C') C.push(i); else if(a=='p') p.push(i); else if(a=='c') c.push(i); } while(!x.empty()&&!t.empty()&&!C.empty()&&!p.empty()&&!c.empty()) { int xx=x.front(); int tt=t.front(); int CC=C.front(); int pp=p.front(); int cc=c.front(); while(tt<xx) { t.pop(); if(t.empty()) tt=maxn; else tt=t.front(); } while(CC<tt) { C.pop(); if(C.empty()) CC=maxn; else CC=C.front(); } while(pp<CC) { p.pop(); if(p.empty()) pp=maxn; else pp=p.front(); } while(cc<pp) { c.pop(); if(c.empty()) cc=maxn; else cc=c.front(); } // cout<<xx<<" "<<tt<<" "<<CC<<" "<<pp<<" "<<cc<<endl; if(!x.empty()&&!t.empty()&&!C.empty()&&!p.empty()&&!c.empty()) { ans++; x.pop();t.pop();C.pop();p.pop();c.pop(); } } printf("%d\n",ans); } return 0; }