标签:des style blog http color io os ar java
大模拟:
1》saygoodbye要先对 always on top 的人说
2》对没有说过话的不要说good bye
3》用long long
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.
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <set> using namespace std; typedef long long int LL; const int INF=0x3f3f3f3f; const int HEAD=0; const int TAIL=6400; struct CHART { int pro,front,back; LL w; }chat[6500]; int n,x,id; int alwayson; set<int> pc; char cmd[50]; void init() { id=1;pc.clear();alwayson=-1; memset(chat,0,sizeof(chat)); chat[HEAD].front=HEAD; chat[HEAD].back=TAIL; chat[TAIL].front=HEAD; chat[TAIL].back=TAIL; chat[HEAD].pro=-INF-1; chat[TAIL].pro=-INF-1; } void Add(int u) { if(pc.count(u)) { puts("same priority."); return ; } pc.insert(u); chat[id].w=0; chat[id].pro=u; chat[id].front=chat[TAIL].front; chat[id].back=TAIL; chat[chat[TAIL].front].back=id; chat[TAIL].front=id; id++; puts("success."); } void Close(int u) { if(pc.count(u)==0) { puts("invalid priority."); return ; } pc.erase(u); if(alwayson==u) alwayson=-1; int pos=HEAD; for(pos=HEAD;pos!=TAIL;pos=chat[pos].back) { if(chat[pos].pro==u) break; } int bc=chat[pos].back; int ft=chat[pos].front; chat[bc].front=ft; chat[ft].back=bc; printf("close %d with %I64d.\n",chat[pos].pro,chat[pos].w); } void Chat(int w) { if(chat[HEAD].back==TAIL) { puts("empty."); return ; } puts("success."); int u=-1; if(alwayson!=-1) u=alwayson; else u=chat[chat[HEAD].back].pro; int pos=HEAD; for(pos=HEAD;pos!=TAIL;pos=chat[pos].back) { if(chat[pos].pro==u) break; } chat[pos].w+=w; } void Rotate(int x) { if(x<1||x>pc.size()) { puts("out of range."); return ; } puts("success."); int pos=HEAD,i=0; for(pos=HEAD;i<x&&pos!=TAIL;pos=chat[pos].back,i++) ; ///split int bc=chat[pos].back; int ft=chat[pos].front; chat[bc].front=ft; chat[ft].back=bc; ///merge chat[pos].front=HEAD; chat[pos].back=chat[HEAD].back; chat[chat[HEAD].back].front=pos; chat[HEAD].back=pos; } void Prior() { if(chat[HEAD].back==TAIL) { puts("empty."); return ; } puts("success."); int pos=HEAD; int mxp=HEAD; for(pos=HEAD;pos!=TAIL;pos=chat[pos].back) { if(chat[pos].pro>chat[mxp].pro) { mxp=pos; } } pos=mxp; ///split int bc=chat[pos].back; int ft=chat[pos].front; chat[bc].front=ft; chat[ft].back=bc; ///merge chat[pos].front=HEAD; chat[pos].back=chat[HEAD].back; chat[chat[HEAD].back].front=pos; chat[HEAD].back=pos; } void Choose(int u) { if(pc.count(u)==0) { puts("invalid priority."); return ; } puts("success."); int pos=HEAD; for(pos=HEAD;pos!=TAIL;pos=chat[pos].back) { if(chat[pos].pro==u) break; } ///split int bc=chat[pos].back; int ft=chat[pos].front; chat[bc].front=ft; chat[ft].back=bc; ///merge chat[pos].front=HEAD; chat[pos].back=chat[HEAD].back; chat[chat[HEAD].back].front=pos; chat[HEAD].back=pos; } void Top(int u) { if(pc.count(u)==0) { puts("invalid priority."); return ; } puts("success."); alwayson=u; } void Untop() { if(alwayson==-1) { puts("no such person."); return ; } alwayson=-1; puts("success."); } void saybyebye() { if(alwayson!=-1) { int p=HEAD; for(p=HEAD;p!=TAIL;p=chat[p].back) { if(chat[p].pro==alwayson) break; } if(chat[p].w) printf("Bye %d: %I64d\n",chat[p].pro,chat[p].w); } int pos=HEAD; for(pos=chat[HEAD].back;pos!=TAIL;pos=chat[pos].back) { if(chat[pos].pro!=alwayson&&chat[pos].w) printf("Bye %d: %I64d\n",chat[pos].pro,chat[pos].w); } } int main() { int T_T; scanf("%d",&T_T); while(T_T--) { init(); scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%s",cmd); printf("Operation #%d: ",i+1); if(strcmp(cmd,"Add")==0) { int u; scanf("%d",&u); Add(u); } else if(strcmp(cmd,"Close")==0) { int u; scanf("%d",&u); Close(u); } else if(strcmp(cmd,"Chat")==0) { int u; scanf("%d",&u); Chat(u); } else if(strcmp(cmd,"Rotate")==0) { int u; scanf("%d",&u); Rotate(u); } else if(strcmp(cmd,"Prior")==0) { Prior(); } else if(strcmp(cmd,"Choose")==0) { int u; scanf("%d",&u); Choose(u); } else if(strcmp(cmd,"Top")==0) { int u; scanf("%d",&u); Top(u); } else if(strcmp(cmd,"Untop")==0) { Untop(); } } saybyebye(); } return 0; }
标签:des style blog http color io os ar java
原文地址:http://blog.csdn.net/ck_boss/article/details/40385905