题目链接
https://acm.bnu.edu.cn/v3/contest_show.php?cid=8504#problem/C
代码如下:
#include <iostream> #include <algorithm> #include <stdio.h> #include <cstring> #include <queue> #include <bitset> #include <set> #include <map> using namespace std; typedef long long LL; const int MAXN = 1e6+5; struct Node { string s; int time; int d; } a[MAXN]; bool cmp(Node a, Node b) { if(a.d == b.d) return a.time > b.time; return a.d > b.d; } struct cmp2 { bool operator()(const Node a, const Node b)const { if(a.d == b.d) return a.time > b.time; return a.d > b.d; } }; struct cmp1 { bool operator()(const Node a, const Node b)const { if(a.d == b.d) return a.time < b.time; return a.d < b.d; } }; set<Node,cmp1>se1; set<Node,cmp2>se2; map<string,Node>mp; string s; int main() { int n, m; while(~scanf("%d",&n)) { se1.clear(); se2.clear(); mp.clear(); double tp = 1.0*n*0.2; int nn = (int)tp; int tn = n; for(int i=1; i<=tn; i++) { a[i].time = i; cin>>a[i].s>>a[i].d; mp[a[i].s] = a[i]; } sort(a+1, a+1+tn, cmp); for(int i=1; i<=nn; i++) se1.insert(a[i]); for(int i=nn+1; i<=n; i++) se2.insert(a[i]); scanf("%d",&m); Node tmp; for(int i=tn+1; i<=tn+m; i++) { char op; cin>>op; if(op == '-') { cin>>s; tmp = mp[s]; if(se1.erase(tmp)) nn--; se2.erase(tmp); if(nn>(int)(1.0*(n-1)*0.2)) { nn--; tmp=*se1.begin(); se1.erase(tmp); se2.insert(tmp); cout<<tmp.s; printf(" is not working now. "); } n--; if(nn<(int)(1.0*(n)*0.2)) { nn++; tmp=*se2.begin(); se1.insert(tmp); se2.erase(tmp); cout<<tmp.s; printf(" is working hard now. "); } } else///++ { cin>>a[i].s>>a[i].d; a[i].time=i; mp[a[i].s]=a[i]; //cout<<nn<<" "<<n<<endl; if(nn<(int)(1.0*(n+1)*0.2))///+0.2 { if(a[i].d>(*se2.begin()).d||a[i].d==(*se2.begin()).d&&a[i].time>(*se2.begin()).time) { se1.insert(a[i]); cout<<a[i].s; printf(" is working hard now. "); } else { tmp=*se2.begin(); se2.erase(tmp); se1.insert(tmp); se2.insert(a[i]); cout<<a[i].s; printf(" is not working now. "); cout<<tmp.s; printf(" is working hard now. "); } nn++; //cout<<"nn"<<nn<<endl; } else///=0.2 { if(nn!=0) { tmp=*se1.begin(); if(a[i].d>tmp.d||a[i].d==tmp.d&&a[i].time>tmp.time) { se1.erase(tmp); se1.insert(a[i]); se2.insert(tmp); cout<<a[i].s; printf(" is working hard now. "); cout<<tmp.s; printf(" is not working now. "); } else { se2.insert(a[i]); // se2.erase(tmp); //se1.insert(tmp); cout<<a[i].s; printf(" is not working now. "); //cout<<tmp.s; //printf(" is working hard now. "); /// } } else { tmp=*se2.begin(); if((int)(1.0*(n+1)*0.2)>0) { if(a[i].d>tmp.d||a[i].d==tmp.d&&a[i].time>tmp.time) { se1.insert(a[i]); cout<<a[i].s; printf(" is working hard now. "); } else { se2.erase(tmp); se2.insert(a[i]); se1.insert(tmp); cout<<a[i].s; printf(" is not working now. "); cout<<tmp.s; printf(" is working hard now. "); } } else { se2.insert(a[i]); cout<<a[i].s; printf(" is not working now. "); } } } n++; }///++ } } return 0; }