We don't wanna work!
作者:互联网
We don't wanna work!
[JAG Asia 2016]
两个set,一个代表工作的,一个代表不工作的
其实是一个很简单的模拟,但是我竟然排序之前标号。。。。
检查代码的时候要从头开始检查。。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
struct node
{
char s[25];
int ti,fen;
bool operator<(const node&r)const
{
if(fen==r.fen)
{
return ti>r.ti;
}
return fen>r.fen;
}
} s[maxn],tmp;
set<node>st,stt;
set<node>::iterator it;
map<string,int>mp;
char str[25];
char op[5];
int p;
void solve()
{
if(st.size()>p)
{
it=st.end();
--it;
tmp=*it;
cout<<tmp.s<<" is not working now."<<endl;
st.erase(tmp);
stt.insert(tmp);
}
else if(st.size()<p)
{
it=stt.begin();
tmp=*it;
cout<<tmp.s<<" is working hard now."<<endl;
stt.erase(tmp);
st.insert(tmp);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
int cnt=0,tag=0,k;
p=n*0.2;
for(int i=1; i<=n; ++i)
{
cin>>s[i].s>>k;
s[i].fen=k;
s[i].ti=i;
}
sort(s+1,s+1+n);
for(int i=1; i<=n; ++i)
{
mp[s[i].s]=++cnt;
tag++;
if(i<=p)
{
st.insert(s[i]);
}
else
{
stt.insert(s[i]);
}
}
int m;
cin>>m;
int id;
while(m--)
{
cin>>op;
tag++;
if(op[0]=='+')
{
n++;
p=n*0.2;
cin>> str>>k;
if(mp.count(str))
{
id=mp[str];
s[id].ti=tag;
s[id].fen=k;
}
else
{
mp[str]=++cnt;
s[cnt].fen=k;
s[cnt].ti=tag;
strcpy(s[cnt].s,str);
id=cnt;
}
if(st.empty())
{
if(p>0&&k>=(*stt.begin()).fen)
{
st.insert(s[id]);
cout<<s[id].s<<" is working hard now."<<endl;
}
else
{
stt.insert(s[id]);
cout<<s[id].s<<" is not working now."<<endl;
}
}
else
{
it=st.end();
--it;
if(k>=(*it).fen||(st.size()<p&&k>=(*stt.begin()).fen))
{
st.insert(s[id]);
cout<<s[id].s<<" is working hard now."<<endl;
}
else
{
stt.insert(s[id]);
cout<<s[id].s<<" is not working now."<<endl;
}
}
solve();
}
else
{
n--;
p=n*0.2;
cin>>str;
id=mp[str];
if(st.find(s[id])!=st.end())
{
st.erase(s[id]);
}
else
{
stt.erase(s[id]);
}
solve();
}
}
return 0;
}
标签:cnt,don,fen,work,st,int,str,wanna,id 来源: https://www.cnblogs.com/smallocean/p/11518400.html