题目链接:

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. linux 系统运行级别一般为 0-6,请分别写出每个级别的含义

    每个运行级别的含义 0   关机模式(不要把启动级别  运行级别设置为0) 1   单用户模式 2   无NFS多用户模式 3   文本模式(命令行模式,完整的多用户模式) 4   未使用的 5   ...

  2. 记一次Apache Carbondata PR的经历

     前言 前段时间有幸接触到Apache Carbondata,试用过程中发现了一个小小的问题,并且又很快的定位到了问题.然后在社区群里反映了下,负责人问愿不愿意提个JIRA,PR,然后我在没有任何开源 ...

  3. ubuntu 9.10 切换到root用户

    昨天装了ubuntu9.10,登陆后是普通用户,操作不方便,上网上查了资料,有很多方法,我发现最简单的方法 有些资料说,ubuntu每次重启root密码是随机的(当你没有设置密码时), 打开终端: $ ...

  4. linux-2.6内核驱动学习——jz2440之输入子系统

    如果按照上一篇记录的那样,只有本公司的人或者自己才能使用驱动.想写出一个通用的驱动程序,让其他应用程序来无缝移植,需要使用现成的驱动——输入子系统. /drivers/input/input.c #d ...

  5. Python数值运算与赋值的快捷方式

    一种比较常见的操作是对一个变量进行一项数学运算并将运算得出的结果返回给这个变量,因此对于这类运算通常有如下的快捷表达方式: a = 2a = a * 3 同样也可写作: a = 2a *= 3 要注意 ...

  6. Linux下onvif客户端获取ipc摄像头 GetStreamUri:rtsp地址(h264、h265)

    GetStreamUri:rtsp地址 鉴权:但是在使用这个接口之前是需要鉴权的.ONVIF协议规定,部分接口需要鉴权,部分接口不需要鉴权,在调用需要鉴权的接口时不使用鉴权,会导致接口调用失败.实现鉴 ...

  7. python基础学习1-SET 集合

    # -*- coding:utf-8 -*- set集合 无序不重复的序列 se = {"a","b","c"} #创建SET集合 prin ...

  8. 10-[协程] greenlet模块、 gevent模块

    1.greenlet模块:实现20个任务切换 如果我们在单个线程内有20个任务,要想实现在多个任务之间切换,使用greenlet模块可以非常简单地实现这20个任务直接的切换 使用yield生成器的方式 ...

  9. 25-[jQuery]-事件

    重点:jQuery事件绑定on().bind()与delegate() 方法详解 1.jquery的事件 <!DOCTYPE html> <html lang="en&qu ...

  10. 洛咕 P3961 [TJOI2013]黄金矿工

    甚至都不是树形背包= = 把每条线抠出来,这一条线就是个链的依赖关系,随便背包一下 // luogu-judger-enable-o2 #include<bits/stdc++.h> #d ...