2016弱校联盟十一专场10.3 C.We don't wanna work!(集合操作)
来源:互联网 发布:淘宝电动车加热手套 编辑:程序博客网 时间:2024/06/05 05:20
传送门
Problem C
We don’t wanna work!
Input: Standard Input
Time Limit: See AtCoder
ACM is an organization of programming contests. The purpose of ACM does not matter to you.
The only important thing is that workstyles of ACM members are polarized: each member is
either a workhorse or an idle fellow.
Each member of ACM has a motivation level. The members are ranked by their motivation
levels: a member who has a higher motivation level is ranked higher. When several members
have the same value of motivation levels, the member who joined ACM later have a higher rank.
The top 20% highest ranked members work hard, and the other (80%) members never (!) work.
Note that if 20% of the number of ACM members is not an integer, its fraction part is rounded
down.
You, a manager of ACM, tried to know whether each member is a workhorse or an idle fellow to
manage ACM. Finally, you completed to evaluate motivation levels of all the current members.
However, your task is not accomplished yet because the members of ACM are dynamically
changed from day to day due to incoming and outgoing of members. So, you want to record
transitions of members from workhorses to idle fellows, and vice versa.
You are given a list of the current members of ACM and their motivation levels in chronological
order of their incoming date to ACM. You are also given a list of incoming/outgoing of members
in chronological order.
Your task is to write a program that computes changes of workstyles of ACM members.
Input
The first line of the input contains a single integer N (1 ≤ N ≤ 50,000) that means the number
of initial members of ACM. The (i + 1)-th line of the input contains a string si and an integer
ai (0 ≤ ai ≤ 105
), separated by a single space. si means the name of the i-th initial member
and ai means the motivation level of the i-th initial member. Each character of si
is an English
letter, and 1 ≤ |si
| ≤ 20. Note that those N lines are ordered in chronological order of incoming
dates to ACM of each member.
The (N + 2)-th line of the input contains a single integer M (1 ≤ M ≤ 20,000) that means the
number of changes of ACM members. The (N + 2 + j)-th line of the input contains information
of the j-th incoming/outgoing member. When the j-th information represents an incoming of a
member, the information is formatted as “+ tj bj”, where tj is the name of the incoming member
7
and bj (0 ≤ bj ≤ 105
) is his motivation level. On the other hand, when the j-th information
represents an outgoing of a member, the information is formatted as “- tj”, where tj means the
name of the outgoing member. Each character of tj is an English letter, and 1 ≤ |tj | ≤ 20.
Note that uppercase letters and lowercase letters are distinguished. Note that those M lines are
ordered in chronological order of dates when each event happens.
No two incoming/outgoing events never happen at the same time. No two members have the
same name, but members who left ACM once may join ACM again.
Output
Print the log, a sequence of changes in chronological order. When each of the following four
changes happens, you should print a message corresponding to the type of the change as follows:
• Member name begins to work hard : “name is working hard now.”
• Member name begins to not work : “name is not working now.”
For each incoming/outgoing, changes happen in the following order:
1. Some member joins/leaves.
2. When a member joins, the member is added to either workhorses or idle fellows.
3. Some member may change from a workhorse to an idle fellow and vice versa. Note that
there are no cases such that two or more members change their workstyles at the same
time.
Sample Input 1
4
Durett 7
Gayles 3
Facenda 6
Daughtery 0
1
+ Mccourtney 2
Output for the Sample Input 1
Mccourtney is not working now.
Durett is working hard now.
8
Initially, no member works because 4 ×20% < 1. When one member joins ACM, Durrett begins
to work hard.
Sample Input 2
3
Burdon 2
Orlin 8
Trumper 5
1
+ Lukaszewicz 7
Output for the Sample Input 2
Lukaszewicz is not working now.
No member works.
Sample Input 3
5
Andy 3
Bob 4
Cindy 10
David 1
Emile 1
3
+ Fred 10
- David
+ Gustav 3
Output for the Sample Input 3
Fred is working hard now.
Cindy is not working now.
Gustav is not working now.
9
Sample Input 4
7
Laplant 5
Varnes 2
Warchal 7
Degregorio 3
Chalender 9
Rascon 5
Burdon 0
7
+ Mccarroll 1
- Chalender
+ Orlin 2
+ Chalender 1
+ Marnett 10
- Chalender
+ Chalender 0
Output for the Sample Input 4
Mccarroll is not working now.
Warchal is working hard now.
Orlin is not working now.
Chalender is not working now.
Marnett is working hard now.
Warchal is not working now.
Chalender is not working now.
Warchal is working hard now.
Some member may repeat incoming and outgoing.
Sample Input 5
4
Aoba 100
Yun 70
Hifumi 120
Hajime 50
2
- Yun
- Aoba
10
Output for the Sample Input 5
(blank)
题目大意:
ACM协会中有
解题思路:
就是按照题目大意,开两个集合,一个是
#include <iostream>#include <algorithm>#include <stdio.h>#include <cstring>#include <queue>#include <bitset>#include <set>#include <map>using namespace std;typedef long long LL;const int MAXN = 1e6+5;struct Node{ string s; int time; int d;} a[MAXN];bool cmp(Node a, Node b){ if(a.d == b.d) return a.time > b.time; return a.d > b.d;}struct cmp2{ bool operator()(const Node a, const Node b)const { if(a.d == b.d) return a.time > b.time; return a.d > b.d; }};struct cmp1{ bool operator()(const Node a, const Node b)const { if(a.d == b.d) return a.time < b.time; return a.d < b.d; }};set<Node,cmp1>se1;set<Node,cmp2>se2;map<string,Node>mp;string s;int main(){ int n, m; while(~scanf("%d",&n)) { se1.clear(); se2.clear(); mp.clear(); double tp = 1.0*n*0.2; int nn = (int)tp; int tn = n; for(int i=1; i<=tn; i++) { a[i].time = i; cin>>a[i].s>>a[i].d; mp[a[i].s] = a[i]; } sort(a+1, a+1+tn, cmp); for(int i=1; i<=nn; i++) se1.insert(a[i]); for(int i=nn+1; i<=n; i++) se2.insert(a[i]); scanf("%d",&m); Node tmp; for(int i=tn+1; i<=tn+m; i++) { char op; cin>>op; if(op == '-') { cin>>s; tmp = mp[s]; if(se1.erase(tmp)) nn--; se2.erase(tmp); if(nn>(int)(1.0*(n-1)*0.2)) { nn--; tmp=*se1.begin(); se1.erase(tmp); se2.insert(tmp); cout<<tmp.s; printf(" is not working now.\n"); } n--; if(nn<(int)(1.0*(n)*0.2)) { nn++; tmp=*se2.begin(); se1.insert(tmp); se2.erase(tmp); cout<<tmp.s; printf(" is working hard now.\n"); } } else///++ { cin>>a[i].s>>a[i].d; a[i].time=i; mp[a[i].s]=a[i]; if(nn<(int)(1.0*(n+1)*0.2))///+0.2 { if(a[i].d>(*se2.begin()).d||a[i].d==(*se2.begin()).d&&a[i].time>(*se2.begin()).time) { se1.insert(a[i]); cout<<a[i].s; printf(" is working hard now.\n"); } else { tmp=*se2.begin(); se2.erase(tmp); se1.insert(tmp); se2.insert(a[i]); cout<<a[i].s; printf(" is not working now.\n"); cout<<tmp.s; printf(" is working hard now.\n"); } nn++; //cout<<"nn"<<nn<<endl; } else///=0.2 { if(nn!=0) { tmp=*se1.begin(); if(a[i].d>tmp.d||a[i].d==tmp.d&&a[i].time>tmp.time) { se1.erase(tmp); se1.insert(a[i]); se2.insert(tmp); cout<<a[i].s; printf(" is working hard now.\n"); cout<<tmp.s; printf(" is not working now.\n"); } else { se2.insert(a[i]); cout<<a[i].s; printf(" is not working now.\n"); } } else { tmp=*se2.begin(); if((int)(1.0*(n+1)*0.2)>0) { if(a[i].d>tmp.d||a[i].d==tmp.d&&a[i].time>tmp.time) { se1.insert(a[i]); cout<<a[i].s; printf(" is working hard now.\n"); } else { se2.erase(tmp); se2.insert(a[i]); se1.insert(tmp); cout<<a[i].s; printf(" is not working now.\n"); cout<<tmp.s; printf(" is working hard now.\n"); } } else { se2.insert(a[i]); cout<<a[i].s; printf(" is not working now.\n"); } } } n++; }///++ } } return 0;}
- 2016弱校联盟十一专场10.3 C.We don't wanna work!(集合操作)
- 2016弱校联盟十一专场10.3 We don't wanna work!
- BNUOJ 52308 2016弱校联盟 10月3日场 We don’t wanna work! 双set维护 模拟
- JAG Practice2016-C-We don't wanna work!-模拟
- We don't wanna work! STL应用
- bnu52308 We don't wanna work! 【模拟+set】
- Blocks(弱校联盟十一专场)
- UmBasketella(弱校联盟十一专场)
- 2016弱校联盟十一专场10.3(12点场)
- 2016弱校联盟十一专场10.3,BNU52308,大模拟
- 2016弱校联盟十一专场10.3 ABest Matched Pair(水)
- (2016 弱校联盟十一专场10.3) Similarity of Subtrees DFS + hash
- 2016弱校联盟十一专场10.2 Longest Increasing Subsequence
- [Contests]2016弱校联盟十一专场10.7
- (2016弱小联盟十一专场10.3)Parentheses 找规律
- Parentheses(弱校联盟十一专场)字典序
- Minimum’s Revenge(弱校联盟十一专场)
- Mr. Frog’s Problem(弱校联盟 十一专场)
- poj 1088 滑雪(beta)
- uc/os II读书笔记(2)
- Leetcode-34. Search for a Range
- POJ-2736 Housewife Wind(树链剖分)
- VHDL快速入门一
- 2016弱校联盟十一专场10.3 C.We don't wanna work!(集合操作)
- 运行结果展示方法
- 独立编址与统一编址
- 机房收费系统——组合窗体
- C++primer 顺序容器(1)
- 关于IP地址
- 剑指offer:二叉搜索树的后序遍历序列(java)
- Support Vector Machines(SVM) vs Logistic Regression(LR)
- 网络编程学习笔记一:Socket编程