题目链接:

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. 面向对象之static关键字

    static概念 static它是静态修饰符,一般用来修饰类中的成员. static特点 1.多个对象共享一个static成员变量.一个对象将static成员变量值修改了,其他对象中的static成员 ...

  2. React-Native项目中使用Redux

    前言 网上别人的文档都是 直接 就是上redux redux-thunk react-redux ,immutable这样的一套,这个有经验的看还行,新手看就很吃力了,需要了解一步一步的安装redux ...

  3. sqli-labs学习(less-1-less-4)

    学习sqli-labs之前先介绍一些函数,以便于下面的payload看的懂 group_concat函数 将查询出来的多个结果连接成一个字符串结果,用于在一个回显显示多个结果 同理的还有 concat ...

  4. angularjs-ui-router-animation

    html <!DOCTYPE html> <html ng-app="APP"> <head> <title></title& ...

  5. P4171 [JSOI2010]满汉全席

    简要的学了一下2-sat,然而不会输出方案. 就是个sb模板题啦 // luogu-judger-enable-o2 #include<bits/stdc++.h> #define il ...

  6. Object C学习笔记9-字符串NSMutableString

    NSMutableString类继承自NSString,所以在NSString中的方法在NSMutableString都可以使用. NSMutableString和NSString的区别在于NSMut ...

  7. Model详解

    一.数据库操作 Model操作: 创建数据库表结构(建表) 操作数据库表(增删改查) 做一部分的验证(验证) a.建表 1.表字段 AutoField(Field) - int自增列,必须填入参数 p ...

  8. UWP 轨道视图Orbit View

    先看一下效果吧 这是我的Music Tags App里面的效果图,当然你也可以做的比我的更炫. 其实这个效果的实现来自于控件UWP Community Toolkit的OrbitView,所以大家要多 ...

  9. Spring学习(十四)----- Spring Auto Scanning Components —— 自动扫描组件

    一.      Spring Auto Scanning Components —— 自动扫描组件 1.      Declares Components Manually——手动配置componen ...

  10. wordpress4.4+版本自动生成一个768w像素缩略图的解决办法

    4.4版本以后,wordpress增加了响应式图片的功能,目的是让图片能适应手机.平板等不同屏幕,但是我不想要这个功能,把缩略图大小全调成0,function.php里的相关函数全删除了, 上传图片还 ...