标签:des style blog http color io os ar java
现场赛的时候也是被坑了,还以为会精细设计一组牛逼的数据卡时间,还有题目里没说是否聊天字数清零的问题,也是坑,
第一次区域赛,感觉就是题目也没什么特别难的,有时题意也没说清楚,我想旁边的北航那个队应该是跟我想的一样,然后被坑了吧,他们一直没
过这题,不然会是第二?反正跟我没关系
直接模拟,也不用考虑超时,数据是随机的.
需要注意的是,如果关掉一个之后又打开它,聊天字数要清零
top如果不为空就替换
#include<iostream> #include<set> #include<algorithm> #include<queue> #include<map> #include<cstdio> #include<cstring> #include<stack> #include<vector> #include<list> #include<string> using namespace std; list<int>box; set<int>val; map<int,long long>note; vector<int>head; priority_queue<int>MAX; list<int>::iterator it; void debug() { cout<<"yes"<<endl; } void add(int a) { if(val.find(a)!=val.end()) puts("same priority."); else { MAX.push(a); box.push_back(a); val.insert(a); puts("success."); } } void close(int a) { int t; if(val.find(a)==val.end()) puts("invalid priority."); else { it=find(box.begin(),box.end(),a); box.erase(it); val.erase(a); if(head.size()&&head[0]==a) head.clear(); printf("close %d with %lld.\n",a,note[a]); note[a]=0; } } void chat(int a) { if(box.size()==0) puts("empty."); else if(head.size()) { note[head[0]]+=(long long)a; puts("success."); } else { note[*box.begin()]+=(long long)a; puts("success."); } } void Rotate(int a) { int t; if(a>box.size()||a<1) puts("out of range."); else { for(it=box.begin();it!=box.end()&&a>1;it++,a--); t=*it; box.erase(it); box.push_front(t); puts("success."); } } void prior() { int t; if(box.size()==0) puts("empty."); else { while(1) { t=MAX.top(); if(val.find(t)==val.end()) MAX.pop(); else { it=find(box.begin(),box.end(),t); box.erase(it); box.push_front(t); break; } } puts("success."); } } void choose(int a) { int t; if(val.find(a)==val.end()) puts("invalid priority."); else { it=find(box.begin(),box.end(),a); box.erase(it); box.push_front(a); puts("success."); } } void Top(int a) { if(val.find(a)==val.end()) puts("invalid priority."); else { if(head.size()==0) head.push_back(a); else head[0]=a; puts("success."); } } void untop() { if(head.size()) { head.clear(); puts("success."); } else puts("no such person."); } void last() { if(head.size()&&val.find(head[0])!=val.end()&¬e[head[0]]!=0) { it=find(box.begin(),box.end(),head[0]); box.erase(it); printf("Bye %d: %lld\n",head[0],note[head[0]]); } for(it=box.begin();it!=box.end();it++) if(note[*it]!=0) printf("Bye %d: %lld\n",*it,note[*it]); while(MAX.size()) MAX.pop(); head.clear(); val.clear(); box.clear(); note.clear(); } int main() { //freopen("in","r",stdin); //freopen("out","w",stdout); string s; int i,T,n,t; cin>>T; while(T--) { cin>>n; for(i=1;i<=n;i++) { cin>>s; printf("Operation #%d: ",i); if(s=="Add") { cin>>t; add(t); } else if(s=="Close") { cin>>t; close(t); } else if(s=="Chat") { cin>>t; chat(t); } else if(s=="Rotate") { cin>>t; Rotate(t); } else if(s=="Prior") { prior(); } else if(s=="Choose") { cin>>t; choose(t); } else if(s=="Top") { cin>>t; Top(t); } else untop(); } last(); } return 0; }
1 18 Prior Add 1 Chat 1 Add 2 Chat 2 Top 2 Chat 3 Untop Chat 4 Choose 2 Chat 5 Rotate 2 Chat 4 Close 2 Add 3 Prior Chat 2 Close 1
Operation #1: empty. Operation #2: success. Operation #3: success. Operation #4: success. Operation #5: success. Operation #6: success. Operation #7: success. Operation #8: success. Operation #9: success. Operation #10: success. Operation #11: success. Operation #12: success. Operation #13: success. Operation #14: close 2 with 8. Operation #15: success. Operation #16: success. Operation #17: success. Operation #18: close 1 with 11. Bye 3: 2HintThis problem description does not relate to any real person in THU.
标签:des style blog http color io os ar java
原文地址:http://blog.csdn.net/stl112514/article/details/40382365