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[], ...
随机推荐
- 51Nod 欢乐手速场1 A Pinball[DP 线段树]
Pinball xfause (命题人) 基准时间限制:1 秒 空间限制:262144 KB 分值: 20 Pinball的游戏界面由m+2行.n列组成.第一行在顶端.一个球会从第一行的某一列出发 ...
- 修改XCode默认工程为使用Xib
概述 自从XCode5开始,当创建一个带有View的iPhone项目时,默认采用了StoryBoards,本文主要是讲解如何手动修改使其切换到使用xib来布局. 修改步骤 1.先将Main.story ...
- qt中的tcp编程
server .server.h #define DIALOG_H #include <QDialog> #include <QTcpServer> #include < ...
- 【Oracle】虚拟表Dual
Dual是个虚拟表,用来构成SELECT语句的语法规则,Oracle保证Dual里面永远只有一条记录.可以用它来做很多事情,例如,查看当前用户:用来调用系统函数:得到序列的下一个值或者当前值:可以用作 ...
- 观察者模式—jdk自带源码分析
一:观察者模式简介 二:jdk实现观察者模式的源码 三:实际例子 四:观察者模式的优点和不足 五:总结 一:观察者模式简介 有时又被称为发布(publish )-订阅(Subscribe)模式.模型- ...
- HTTPS的原理解析
http://www.cnblogs.com/alisecurity/p/5939336.html 外加文档
- Linux ipip隧道及实现
一.IP隧道技术 IP隧道技术:是路由器把一种网络层协议封装到另一个协议中以跨过网络传送到另一个路由器的处理过程.IP 隧道(IP tunneling)是将一个IP报文封装在另一个IP报文的技术,这可 ...
- php使用file_get_contents请求微信接口失败
windows下的php,只需要到php.ini中把extension=php_openssl.dll前面的;删掉,重启服务就可以了.Linux下的PHP,就必须安装openssl模块,安装好了以后就 ...
- jq实现数字增加或者减少的动画
效果图: 1.HTML: <div class="up"></div> <br> <div class="down"& ...
- 解决java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList这个问题
今天使用SSM框架,用@ResponseBody注解,出现了这个问题 java.lang.IllegalArgumentException: No converter found for return ...