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;
}

最新文章

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

热门文章

  1. Javascript声明和使用变量
  2. 调用约定__stdcall / __cdecl
  3. Arduino IIC 主从设备连接通信
  4. 数组 bash shell
  5. jdk1.6以后 对synchronized锁做了哪些优化
  6. linux centos 7 防火墙相关
  7. 干货 | TiDB Operator实践
  8. VUE 引用公共样式
  9. java RSA 加密解密
  10. 2020 年最流行的 Java 开发技术