We don't wanna work!
2024-09-06 07:41:56
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;
}
最新文章
- FMX保存JPG格式的Stream
- APS.net controller
- 内存管理单元(MMU)和协处理器CP15介绍(转)
- 2014 UESTC 暑前集训队内赛(3) 部分解题报告
- 关于那些难改的bug
- js闭包用法
- Spring 3.0 + Atomikos构建jta分布式事务
- Hadoop无法上传文件查找原因
- [bzoj2594][Wc2006]水管局长数据加强版 (lct)
- 【Python 11】汇率兑换4.0(函数)
- <;转>;性能测试指标
- 【高速接口-RapidIO】2、RapidIO串行物理层的包与控制符号
- Windows Server 2012 IIS 8 - 安装SSL证书
- [模板]KMP算法
- macOS在virtualenv中使用wxPython报错
- Windows PowerShell 入門(10)-デバッグ編
- CSS font-family字体大合集
- win10下vs2015编译的程序如何运行在win7等系统(无需安装Redistributable)
- easyui datagrid自定义按钮列,即最后面的操作列
- 快速零配置迁移 API 适配 iOS 对 IPv6 以及 HTTPS 的要求