2016弱校联盟十一专场10.3 We don't wanna work!
能把 not working now 写成 not working hard now
还查一晚上也是没谁了
我的做法是维护两个set 分别是前20% 和后80%
#include<iostream>
#include<algorithm>
#include<set>
#include<cmath>
#include<map>
#include<cstdio>
using namespace std;
#define sz(X) ((int)X.size())
int N,M;
char nam[70005][25];
map<string, int> mp;
struct Node{
int id; int val; int ti;
Node(int a=0, int b=0, int c=0):id(a),val(b),ti(c){}
bool operator < (const Node &v) const{
if(val != v.val) return val > v.val;
return ti > v.ti;
}
bool operator == (Node v) const{
return id==v.id && val==v.val && ti==v.ti;
}
}mem[70005];
set<Node> s1; set<Node> s2;
set<Node>::iterator it1,it,it2;
int main(){
while(~scanf("%d",&N)) {
mp.clear();
s1.clear(); s2.clear();
for(int i = 0; i < N; ++i) {
int a; scanf("%s %d",nam[i], &a);
s2.insert(Node(i,a,i));
mem[i] = Node(i,a,i);
mp[nam[i]] = i;
}
int tot = N;
int K = floor(N/5);
while(K--) {
it = s2.begin();
Node y = *it;
s2.erase(y);
s1.insert(y);
}
scanf("%d",&M);
for(int i = N; i < N+M; ++i) {
char s[5]; scanf("%s",s);
if(s[0] == '+') {
int a; scanf("%s %d",nam[i],&a);
Node tt = Node(i,a,i);
mem[i] = tt; mp[nam[i]] = i;
tot ++;
int x = floor(tot/5); int y = tot-x;
if(sz(s2) == y-1) {
s1.insert(tt);
it = --s1.end(); Node t2 = *it; s1.erase(it);
if(t2 == tt) {
printf("%s is not working now.\n",nam[i]);
s2.insert(t2);
}else {
printf("%s is working hard now.\n",nam[i]);
printf("%s is not working now.\n",nam[t2.id]);
s2.insert(t2);
}
}else {
s2.insert(tt);
it = s2.begin(); Node t2 = *it; s2.erase(it);
if(t2 == tt) {
printf("%s is working hard now.\n",nam[i]);
s1.insert(t2);
}else {
printf("%s is not working now.\n",nam[i]);
printf("%s is working hard now.\n",nam[t2.id]);
s1.insert(t2);
}
}
}else if(s[0] == '-') {
char _s[25];
scanf("%s",_s);
Node tt = mem[mp[_s]];
it1 = s1.find(tt); it2 = s2.find(tt);
if(it1 != s1.end()) s1.erase(it1);
else s2.erase(it2);
tot--;
int x = floor(tot/5); int y = tot-x;
if(sz(s1) > x) {
it = --s1.end(); Node t2 = *it;
printf("%s is not working now.\n",nam[t2.id]);
s1.erase(it); s2.insert(t2);
}
if(sz(s2) > y) {
it = s2.begin(); Node t2 = *it;
printf("%s is working hard now.\n",nam[t2.id]);
s2.erase(it); s1.insert(t2);
}
}
}
}
return 0;
}
2016弱校联盟十一专场10.3 We don't wanna work!的更多相关文章
- 2016弱校联盟十一专场10.3 We don't wanna work!
能把 not working now 写成 not working hard now 还查一晚上也是没谁了 我的做法是维护两个set 分别是前20% 和后80% #include<iostrea ...
- 2016弱校联盟十一专场10.5---As Easy As Possible(倍增)
题目链接 https://acm.bnu.edu.cn/v3/contest_show.php?cid=8506#problem/A problem description As we know, t ...
- 2016弱校联盟十一专场10.3---Similarity of Subtrees(深搜+hash、映射)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52310 problem description Define the depth of a ...
- (2016弱校联盟十一专场10.3) D Parentheses
题目链接 把左括号看成A右括号看成B,推一下就行了.好久之前写的,推到最后发现是一个有规律的序列. #include <bits/stdc++.h> using namespace std ...
- (2016弱校联盟十一专场10.3) B.Help the Princess!
题目链接 宽搜一下就行. #include <iostream> #include<cstdio> #include<cstring> #include<qu ...
- (2016弱校联盟十一专场10.3) A.Best Matched Pair
题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> ...
- 2016弱校联盟十一专场10.3---We don't wanna work!(STL--set的使用)
题目链接 https://acm.bnu.edu.cn/v3/contest_show.php?cid=8504#problem/C 代码如下: #include <iostream> # ...
- 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem description In ICPCCamp, there ar ...
- (2016弱校联盟十一专场10.2) A.Nearest Neighbor Search
题目链接 水题,算一下就行. #include <bits/stdc++.h> using namespace std; typedef long long ll; ll x[],y[], ...
随机推荐
- BZOJ 4408: [Fjoi 2016]神秘数 [主席树]
传送门 题意: 一个可重复数字集合S的神秘数定义为最小的不能被S的子集的和表示的正整数.例如S={1,1,1,4,13},8无法表示为集合S的子集的和,故集合S的神秘数为8.现给定n个正整数a[1]. ...
- 整理一点与排列组合有关的问题[组合数 Stirling数 Catalan数]
都是数学题 思维最重要,什么什么数都没用,DP直接乱搞(雾.. 参考LH课件,以及资料:http://daybreakcx.is-programmer.com/posts/17315.html 做到有 ...
- HDU3488 Tour [有向环覆盖 费用流]
Tour Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submis ...
- Appium的iOS环境搭建
操作系统的名称:Mac OS X操作系统的版本:10.13.3 xcode 版本:9.2 java 版本:java8_161 appium destop版本:1.7.3 接下来我们开始踏上搭建Appi ...
- 关于@Override
首先,来了解一下“重载”和“覆写”的区别: 重载: (1)方法重载是让类以统一的方式处理不同类型数据的一种手段.多个同名函数同时存在,具有不同的参数个数/类型.重载Overloading是一个类中多态 ...
- [Python Study Notes]匿名函数
Python 使用 lambda 来创建匿名函数. lambda这个名称来自于LISP,而LISP则是从lambda calculus(一种符号逻辑形式)取这个名称的.在Python中,lambda作 ...
- ★Linux命令行操作技巧(作为服务器端)
1.统计某个目录下总共有多少个文件(递归统计所有子目录)ls -lR|grep "^-"|wc -l
- 使用CentOS Linux Bridge搭建Vxlan环境
一. 基础环境使用VmWare虚拟两台Linux机器.CentOS 7,Linux内核如下:4.5.3-1.el7.elrepo.x86_64如果内核版本太低,是不支持VxLan的.可以使用一下命令进 ...
- .NET 设计模式的六大原则理论知识
1. 单一职责原则(SRP)(Single Responsibility Principle)2. 里氏替换原则(LSP)(Liskov Substitution Principle)3. 依赖倒置原 ...
- 基于Jquery+Ajax+Json+存储过程 高效分页
在做后台开发中,都会有大量的列表展示,下面给大家给大家分享一套基于Jquery+Ajax+Json+存储过程高效分页列表,只需要传递几个参数即可.当然代码也有改进的地方,如果大家有更好的方法,愿留下宝 ...