2015 Multi-University Training Contest 6 hdu 5360 Hiking
Hiking
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 226 Accepted Submission(s): 126
Special Judge
1. he selects a soda not invited before;
2. he tells soda the number of soda who agree to go hiking by now;
3. soda will agree or disagree according to the number he hears.
Note: beta will always tell the truth and soda will agree if and only if the number he hears is no less than li and no larger than ri, otherwise he will disagree. Once soda agrees to go hiking he will not regret even if the final total number fails to meet some soda's will.
Help beta design an invitation order that the number of soda who agree to go hiking is maximum.
The first contains an integer n (1≤n≤105), the number of soda. The second line constains n integers l1,l2,…,ln. The third line constains n integers r1,r2,…,rn. (0≤li≤ri≤n)
It is guaranteed that the total number of soda in the input doesn't exceed 1000000. The number of test cases in the input doesn't exceed 600.
#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
const int maxn = ;
struct SODA {
int l,r,id;
SODA(int x = ,int y = ,int z = ) {
l = x;
r = y;
id = z;
}
bool operator<(const SODA &t) const {
if(l == t.l) return r < t.r;
return l < t.l;
}
bool operator>(const SODA &t) const {
return r > t.r;
}
} s[maxn];
struct node {
int l,r,id;
};
priority_queue<SODA,vector<SODA>,greater<SODA> >q;
vector<int>ans;
bool vis[maxn];
int main() {
int kase,n;
scanf("%d",&kase);
while(kase--) {
scanf("%d",&n);
for(int i = ; i < n; ++i) {
scanf("%d",&s[i].l);
s[i].id = i + ;
}
for(int i = ; i < n; ++i)
scanf("%d",&s[i].r);
sort(s,s+n);
int agree = ,cur = ;
ans.clear();
bool flag = true;
memset(vis,false,sizeof vis);
while(cur < n && flag) {
while(cur < n && s[cur].l <= agree)
q.push(s[cur++]);
flag = false;
while(!q.empty()) {
int u = q.top().r;
if(u >= agree) {
ans.push_back(q.top().id);
agree++;
flag = true;
vis[q.top().id] = true;
q.pop();
break;
}
q.pop();
}
}
while(!q.empty()) {
int u = q.top().r;
if(u >= agree) {
ans.push_back(q.top().id);
agree++;
vis[q.top().id] = true;
}
q.pop();
}
for(int i = ; i <= n; ++i)
if(!vis[i]) ans.push_back(i);
printf("%d\n",agree);
for(int i = ; i < n; ++i)
printf("%d%c",ans[i],i+==n?'\n':' ');
}
return ;
}
2015 Multi-University Training Contest 6 hdu 5360 Hiking的更多相关文章
- 2015多校第6场 HDU 5360 Hiking 贪心,优先队列
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5360 题意:给定n个人,现在要邀请这些人去远足,但每个人同意邀请的条件是当前已经同意去远足的人数c必须 ...
- HDU 5360 Hiking(优先队列)2015 Multi-University Training Contest 6
Hiking Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total S ...
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
- 2015 Multi-University Training Contest 8 hdu 5385 The path
The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...
- 2015 Multi-University Training Contest 3 hdu 5324 Boring Class
Boring Class Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ
RGCDQ Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple
CRB and Apple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries
CRB and Queries Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
随机推荐
- 最大团&稳定婚姻系列
[HDU] 1530 Maximum Clique 1435 Stable Match 3585 maximum shortest distance 二分+最大团 1522 Marriage is ...
- 解决VTune错误PMU resources currently being used by another profiling tool or process
错误信息: When I ran Hardware Event-based Sampling Analysis 0, it showed the ERROR: Collection failed Co ...
- CCDirector导演类
CCDirector类是Cocos2D-x游戏引擎的核心.它用来创建而且控制着屏幕的显示,同一时候控制场景的显示时间和显示方式. 在整个游戏里一般仅仅有一个导演.游戏的開始.结束.暂停都会调用CCDi ...
- 拥抱Mac之码农篇
拥抱Mac之码农篇 使用Mac大概两年时间.之前用着公司配的一台27寸的iMac.无奈机械硬盘严重拖慢速度,影响工作心情.于是入手Macbook Retina 13.这两年的开发工作所有在Mac上完毕 ...
- oracle 11gR2 如何修改 private ip
1.1 修改 private ip1.1.1 确保crs集群是打开的可以用olsnodes –s 检查集群的状态./olsnodes -sP570a ActiveP570b Active1.1 ...
- [jzoj 6101] [GDOI2019模拟2019.4.2] Path 解题报告 (期望)
题目链接: https://jzoj.net/senior/#main/show/6101 题目: 题解: 设$f_i$表示从节点$i$到节点$n$的期望时间,$f_n=0$ 最优策略就是如果从$i, ...
- java1.8对集合中对象的特有属性进行排序
每天学习一点点,知识财富涨点点 1.创建对象user12 2.编写测试类 3.输出结果 加油!!!!
- 参照实验室这边案例做一个简单的maven webapp项目
流程 : 首先写出一个简单的前端页面. 之后写配置文件.dao.domain等等,注意这里可以使用generator进行自动配置 实验室这边配置文件如下: 其实主要的配置文件就分为6“个”. appl ...
- 使用 async/ await 进行 异步 编程
一.异步函数 异步函数概念. 通常 是 指用 async 修饰 符 声明 的, 可 包含 await 表达式 的 方法 或 匿名 函数 1. 从 语言 的 视角 来看, 这些 await 表达式 正是 ...
- 杂文 | 金沙江创投朱啸虎谈微信小程序
我一直在想怎么去描述和朱啸虎的聊天. 最简单的开头一定是说“独角兽捕手朱啸虎”看好小程序了,这个赛道蕴含了许多无比巨大.充沛的机会,所以约到朱啸虎同学深聊这个赛道的创业.但是这样的开头太平,不好玩.事 ...