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 ...
随机推荐
- ASP.NET-signalR学习笔记
- [Design]制作磨砂效果
比较适合运用到网页或者APP的设计当中,推荐过来和飞特的朋友们一起分享学习了,先来看看最终的效果图吧 具体的制作步骤如下:
- 香蕉派 Banana pi BPI-M2 四核开源单板计算机.
Banana PI BPI-M2 是一款四核高性能单板计算机,Banana PI BPI-M2是一款比树莓派更强悍的四核Android4.4产品. Banana PI BPI-M2兼容性强大,能 ...
- 使用CSStickyHeaderFlowLayout实现头部固定的CollectionView
近期流行的一种界面效果,是瀑布流的header固定,也叫sticky header或者parallax.对于UITableView,能够比較方便地让table header固定,可是对于UIColle ...
- NYOJ_94 cigarettes 递归VS迭代
题目地址 分析: 英文题事实上看懂意思和正常的也都差点儿相同.就算有几个单词不认识也无伤大雅. 一共同拥有n支烟,每天抽k支. 每抽完k支,会得到一仅仅. a组数据. 输入n k的个数.输出一共抽了 ...
- 王立平--Object-c
object-c通常写作objective-c或者obj-c,是依据C语言所衍生出来的语言.继承了C语言的特性,是扩充C的面向对象编程语言. 它主要使用于MacOSX和GNUstep这两个使用Open ...
- Android监听程序自身被卸载
概述: 假设不是一些特殊的情况,我想大家非常少会接触到这个需求.事实上Android的Java部分没有提供对应的接口.这里须要去调用C的代码,也就是说要写JNI了.关于JNI的初识.大家能够去參考我博 ...
- angularjs1-7,供应商
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- BZOJ 2957 分块
思路: 记录每栋楼楼顶与原点连线的斜率 那么一栋楼可见当且仅当前面所有楼的斜率都小于这栋楼 将n栋楼分为√(0.5*n*logn)块 每一块内维护一个单调上升子序列(注意不是LCS) 比如说4 1 2 ...
- Centos上JDK的安装搭建
一.下载 yum search java|grep jdk //查找所有jdk版本 二.选择安装1.8 yum install java-1.8.0-openjdk-src-debug.x86_64 ...