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[], ...
随机推荐
- 【洛谷P4124】[CQOI2016]手机号码
手机号码 数位DP模板题 记忆化搜索: #include<iostream> #include<cstring> #include<cstdio> using na ...
- 【题解】洛谷P1495 曹冲养猪 (中国剩余定理)
洛谷P1495:https://www.luogu.org/problemnew/show/P1495 思路 建立了a个猪圈 有b头猪没有去处 即x≡b(mod a) x即是ans 把所有的关系全部列 ...
- Vue教程:简介(一)
前言 用了这么久的vue了,但是一直没有时间写个系列文章,现在抽一定时间总结下vue的知识点. 首先,Vue 不支持 IE8 及以下版本,因为 Vue 使用了 IE8 无法模拟的 ECMAScript ...
- Javascript文件中的控制器II
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- react(三):容器组件和傻瓜组件
让一个组件只专注于一件事,如果发现让一个组件做的事情太多,就可以把这个组件拆分成多个组件让每一个组件只专注于一件事 <深入浅出react和redux> ---程墨 一个react组件最基本 ...
- oracle快速添加用户及授权
--Oracle使用的是用户管理模式--意味着,Oracle的数据使用用户来分割 --以后开发,我们需要每个项目都需要使用一个用户 --所以:一个数据文件是可以放多个用户的数据的.但是我们开发从数据的 ...
- 带你解析Java类加载机制
目录 Java类加载机制的七个阶段 加载 验证 准备(重点) 解析 初始化(重点) 使用 卸载 实战分析 方法论 树义有话说 在许多Java面试中,我们经常会看到关于Java类加载机制的考察,例如 ...
- DbUtils: JDBC Utility Component Examples翻译
DbUtils:JDBC实用组件实例 这一页提供了一些展示如何使用DbUtils的示例. 基本用法 DbUtils是一个非常小的类库,因此浏览完所有类的javadoc不会花费很长时间.DbUtils的 ...
- Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate failed: Exception getting JDBC Driver: com.mysql.jdbc.Driver (mybatis逆向工程)
springboot整合mybatis时出现的问题 解决方法:在pom.xml中plugin中加入单独依赖Mysql驱动包,问题便可解决 <plugin> <groupId>o ...
- sublime text 3 配置terminal 启动npm
前期工作.安装node.js 配置全家变量 1:ctrl + shift + p 打开 输入intall package 回车 2:安装node.js 插件 3:再安装terminal 4:Prefe ...