BNUOJ 52308 We don't wanna work! set模拟
题目链接:
https://acm.bnu.edu.cn/v3/problem_show.php?pid=52308
We don't wanna work!
Time Limit: 60000msMemory Limit: 524288KB
题意
acm协会的人员按努力值排序,只有前20%(向下取整)的人努力工作,现在会有人员变动(增加一个人进来或减少一个人),人员变动会导致一些人从不努力变成努力或从努力变成不努力,现在给你人员的变动情况,输出对于的日志。
增加一个人:先输出这个人归属,然后输出他加入之后引起的某个人的归属变化。
减少一个人:输出一个人走了以后引起的某个人的归属变化。
题解
用两个set维护下,一个set放不努力,另一个放努力。模拟下就可以了。
插入:先比较不努力人里面最努力的,如果没他努力,就扔不努力里面,否则就扔努力里面,然后调整不努力,努力使得人数比例满足要求。
删除:先看看要删的是努力还是不努力,然后在对应的集合里面删掉,删完之后调整。
代码
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<sstream>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define scf scanf
#define prf printf
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII;
const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-8;
const double PI = acos(-1.0);
//start----------------------------------------------------------------------
map<string, pair<int,int> > mp;
const char msg[2][33]= {"is not working now.","is working hard now."};
struct Node {
int v,t;
string nam;
Node(int v,int t,string nam):v(v),t(t),nam(nam) {}
Node() {}
bool operator <(const Node& tmp)const {
return v>tmp.v||v==tmp.v&&t>tmp.t;
}
};
struct Node2 {
int v,t;
string nam;
Node2(int v,int t,string nam):v(v),t(t),nam(nam) {}
Node2() {}
bool operator <(const Node2& tmp)const {
return v<tmp.v||v==tmp.v&&t<tmp.t;
}
};
int main() {
int n;
set<Node> s1;
set<Node2> s2;
int clk=0,tot=0;
scf("%d",&n);
rep(i,0,n) {
char nam[33];
int v;
scf("%s%d",nam,&v);
mp[nam]=mkp(v,++clk);
if(s1.sz()==0||*s1.begin()<Node(v,clk,nam)) {
s1.insert(Node(v,clk,nam));
} else {
s2.insert(Node2(v,clk,nam));
}
tot++;
int cnt=(int)(tot*0.2+eps);
while(s2.sz()>cnt) {
Node2 x=*s2.begin();
s1.insert(Node(x.v,x.t,x.nam));
s2.erase(s2.begin());
}
while(s2.sz()<cnt) {
Node x=*s1.begin();
s2.insert(Node2(x.v,x.t,x.nam));
s1.erase(s1.begin());
}
}
int m;
scf("%d",&m);
while(m--) {
char nam[33],cmd[2];
int v;
scf("%s%s",cmd,nam);
if(cmd[0]=='+') {
scf("%d",&v);
mp[nam]=mkp(v,++clk);
int flag,flag2=-1;
string buf;
if(s1.sz()==0||*s1.begin()<Node(v,clk,nam)) {
s1.insert(Node(v,clk,nam));
flag=0;
} else {
s2.insert(Node2(v,clk,nam));
flag=1;
}
tot++;
int cnt=(int)(tot*0.2+eps);
while(s2.sz()>cnt) {
Node2 x=*s2.begin();
if(x.v==v&&x.t==clk) flag=0;
else {
flag2=0;
buf=x.nam;
}
s1.insert(Node(x.v,x.t,x.nam));
s2.erase(s2.begin());
}
while(s2.sz()<cnt) {
Node x=*s1.begin();
if(x.v==v&&x.t==clk) flag=1;
else {
flag2=1;
buf=x.nam;
}
s2.insert(Node2(x.v,x.t,x.nam));
s1.erase(s1.begin());
}
prf("%s %s\n",nam,msg[flag]);
if(flag2>=0) prf("%s %s\n",buf.c_str(),msg[flag2]);
} else {
pair<int,int> x=mp[nam];
Node nd=*s1.begin();
if(x.X<nd.v||x.X==nd.v&&x.Y<=nd.t) {
set<Node>::iterator it=s1.lower_bound(Node(x.X,x.Y,nam));
if(it!=s1.end()) s1.erase(it);
} else {
set<Node2>::iterator it=s2.lower_bound(Node2(x.X,x.Y,nam));
if(it!=s2.end()) s2.erase(it);
}
tot--;
int cnt=(int)(tot*0.2+eps);
while(s2.sz()>cnt) {
Node2 x=*s2.begin();
prf("%s %s\n",x.nam.c_str(),msg[0]);
s1.insert(Node(x.v,x.t,x.nam));
s2.erase(s2.begin());
}
while(s2.sz()<cnt) {
Node x=*s1.begin();
prf("%s %s\n",x.nam.c_str(),msg[1]);
s2.insert(Node2(x.v,x.t,x.nam));
s1.erase(s1.begin());
}
}
}
return 0;
}
//end-----------------------------------------------------------------------
BNUOJ 52308 We don't wanna work! set模拟的更多相关文章
- BNUOJ-29357 Bread Sorting 模拟
题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=29357 直接模拟就可以了.. //STATUS:C++_AC_190MS_1884KB # ...
- BNUOJ 52325 Increasing or Decreasing 数位dp
传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...
- bnuoj 24251 Counting Pair
一道简单的规律题,画出二维表将数字分别相加可以发现很明显的对称性 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=24251 #include< ...
- bnuoj 44359 快来买肉松饼
http://www.bnuoj.com/contest/problem_show.php?pid=44359 快来买肉松饼 Time Limit: 5000 ms Case Time Lim ...
- BNUOJ 1006 Primary Arithmetic
Primary Arithmetic 来源:BNUOJ 1006http://www.bnuoj.com/v3/problem_show.php?pid=1006 当你在小学学习算数的时候,老师会教你 ...
- bnuoj 34985 Elegant String DP+矩阵快速幂
题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 We define a kind of strings as elegant s ...
- bnuoj 25659 A Famous City (单调栈)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=25659 #include <iostream> #include <stdio.h ...
- bnuoj 25662 A Famous Grid (构图+BFS)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=25662 #include <iostream> #include <stdio.h ...
- bnuoj 4207 台风(模拟题)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=4207 [题意]:中文题,略 [题解]:模拟 [code]: #include <iostrea ...
随机推荐
- 在jupyter中安装R的kernal
网上有安装完anaconda后可以直接使用conda 命令安装R的kernal,本人电脑上已经安装了anaconda和R,因此使用手动安装的方式安装. 安装环境: windows 8.1 企业版 An ...
- 2017-2018-1 20155338 加分项目——PWD的实现
2017-2018-1 20155338 加分项目--PWD的实现 项目要求 1 学习pwd命令 2 研究pwd实现需要的系统调用(man -k; grep),写出伪代码 3 实现mypwd 4 测试 ...
- git push 每次都要输入用户名密码
添加远程库的时候使用了https的方式..所以每次都要用https的方式push到远程库,速度还慢.. 查看使用的传输协议: git remote -v 重新设置成ssh的方式: git remote ...
- 对Dataguard的三种模式的理解
模式1:最大可保护模式: 必须同步. 模式2:最大可用性模式: 能同步就同步,不能同步就不同步. 模式3:最大性能模式: 异步模式.
- AGC 018 F - Two Trees
F - Two Trees 链接 题意: 给定两棵都是N个节点的有根树,节点均从1~N标号.给每个标号定一个权值(类似一号点的权值是x,那么两棵树中1号点的权值都是x),使在两棵树满足以任意节点为根的 ...
- spring源码学习(一):eclipse导入spring源码
前言 对于一门技术,我们最先是了解它(what),然后再熟练的使用它(how)以及何时用它(when),最后肯定要看透它(why).spring作为Java开发人员可以说是最熟悉不过的了,基本每个Ja ...
- 对大表进行全表更新,导致 Replication 同步数据的过程十分缓慢
在Publisher database中更新一个big table,数据行数是3.4亿多.由于没有更新 clustered Index key,因此,只产生了3.4亿多个Update Commands ...
- 开箱即用 - Memcache缓存
废话少说,先上代码C# memcache Demo memcache 是服务器缓存系统,以键值对方式保存数据到内存中,把对象序列化后,理论上可支持所有的数据类型. 使用情景:怎么用都可以,注意的是它只 ...
- java学习(一) 环境搭建、hello world的demo
本程序媛搞前端的,上班偶有空闲,不妨来学习学习,不然怎么包养小白脸,走上人生巅峰? 说实话,每个语言都相通,有了javascript的基础,并且有了两三年跟java打交道的经验,简单学习下java想必 ...
- 六、Django之表单和类视图-Part 4
一.表单form 为了接收用户的投票选择,我们需要在前端页面显示一个投票界面.让我们重写先前的polls/detail.html文件,代码如下: <h1>{{ question.quest ...