题目链接:

https://acm.bnu.edu.cn/v3/problem_show.php?pid=52308

We don't wanna work!

Time Limit: 60000ms
Memory 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模拟的更多相关文章

  1. BNUOJ-29357 Bread Sorting 模拟

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=29357 直接模拟就可以了.. //STATUS:C++_AC_190MS_1884KB # ...

  2. BNUOJ 52325 Increasing or Decreasing 数位dp

    传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...

  3. bnuoj 24251 Counting Pair

    一道简单的规律题,画出二维表将数字分别相加可以发现很明显的对称性 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=24251 #include< ...

  4. bnuoj 44359 快来买肉松饼

    http://www.bnuoj.com/contest/problem_show.php?pid=44359 快来买肉松饼 Time Limit: 5000 ms     Case Time Lim ...

  5. BNUOJ 1006 Primary Arithmetic

    Primary Arithmetic 来源:BNUOJ 1006http://www.bnuoj.com/v3/problem_show.php?pid=1006 当你在小学学习算数的时候,老师会教你 ...

  6. 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 ...

  7. bnuoj 25659 A Famous City (单调栈)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=25659 #include <iostream> #include <stdio.h ...

  8. bnuoj 25662 A Famous Grid (构图+BFS)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=25662 #include <iostream> #include <stdio.h ...

  9. bnuoj 4207 台风(模拟题)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=4207 [题意]:中文题,略 [题解]:模拟 [code]: #include <iostrea ...

随机推荐

  1. K8S学习心得 == 安装虚拟路由器RouterOS

    使用RouterOS, 搭建虚拟路由器,并且配置多个网关互通.配置步骤如下.   基础配置 1. RouterOS 服务器,设置如下             2. VM 不同网段的设置 == 192. ...

  2. 【Linux】LVM逻辑卷管理和RAID

    LVM概述: 是对磁盘分区进行管理的一种机制 是一种将一个或多个硬盘的分区在逻辑上集合,相当于一个大硬盘来使用,当硬盘的空间不 够使用的时候,可以继续将其它的硬盘的分区加入其中,这样可以实现一种磁盘空 ...

  3. CTF-i春秋网鼎杯第四场部分writeup

    CTF-i春秋网鼎杯第四场部分writeup 因为我们组的比赛是在第四场,所以前两次都是群里扔过来几道题然后做,也不知道什么原因第三场的题目没人发,所以就没做,昨天打了第四场,简直是被虐着打. she ...

  4. SEO优化上首页之搜索引擎用户需求理解

    经过前面<搜索引擎原理SEO优化上首页之网络蜘蛛Spider>和<搜索引擎原理SEO优化上首页之内容处理与创建索引>介绍,搜索引擎已经完成页面抓取和分析,并把原始页面.索引等信 ...

  5. 在myeclipse等IDE中添加本地的dtd与schema约束文件

      *针对没有网络无法正确引入dtd而使用不了提示的问题 (配置完后重启IDE)   window->perferences- > 搜索xml c 找到xml catalog 右边点击 a ...

  6. Linux下开发python django程序(模板设置和载入数据)

    1.添加templates文件夹 2.修改settings.py文件 import os #引用 os模块 BASE_DIR = os.path.dirname(os.path.dirname(os. ...

  7. 深度学习与计算机视觉(11)_基于deep learning的快速图像检索系统

    深度学习与计算机视觉(11)_基于deep learning的快速图像检索系统 作者:寒小阳 时间:2016年3月. 出处:http://blog.csdn.net/han_xiaoyang/arti ...

  8. error: this 'if' clause does not guard... [-Werror=misleading-indentation]

    解决办法就是if语句的下面加{} 报错的 if (!pMem) return LOS_NOK; 修改后 if (!pMem) { return LOS_NOK; }

  9. Linux 挂载 xshell 命令 配置环境变量

  10. [Selenium]如何通过Selenium实现Ctrl+click,即按住Ctrl的同时进行单击操作

    [以下是不负责任的转载……] 在自动化测试的过程中,经常会出现这样的场景: 按住Ctrl的同时,进行单击操作,已达到多选的目的 Actions a = new Actions(driver); a.k ...