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 ...
随机推荐
- Innodb性能优化之参数设置
现在,Innodb是Mysql最多使用的存储引擎.其性能一直广受关注.本文通过基本的参数设置来提高其性能. innodb_buffer_pool_size 缓冲池大小.这是innodb参数中最重要的设 ...
- [jQuery]ajax同步请求在方法内问题
在函数内写$.ajax() 的成功函数中return 的值,并没有return到外层方法返回至
- POJ 2470 Ambiguous permutations(简单题 理解题意)
[题目简述]:事实上就是依据题目描写叙述:A permutation of the integers 1 to n is an ordering of these integers. So the n ...
- OpenLayers3基础教程——OL3 介绍control
概述: 本文讲述的是Ol3中的control的介绍和应用. OL2和OL3 control比較: 相比較Ol2的control,OL3显得特别少,下图分别为Ol2和Ol3的control: Ol2的c ...
- Erlang语言入门
Erlang语言入门 下载Erlang,http://www.erlang.org/downloads 安装之后开始菜单中有Erlang图标,打开之后是Erlang Shell,可以定制喜欢的颜色和字 ...
- Java设计模式透析之 —— 模板方法(Template Method)
今天你还是像往常一样来上班,一如既往地開始了你的编程工作. 项目经理告诉你,今天想在server端添加一个新功能.希望写一个方法.能对Book对象进行处理.将Book对象的全部字段以XML格式进行包装 ...
- Server Tomcat v8.0 Server at localhost was unable to start within 45 seconds. If the server requires
Server Tomcat v8.0 Server at localhost was unable to start within 45 seconds. If the server requires ...
- jqueryui slider
<!doctype html><html lang="en"><head> <meta charset="utf-8" ...
- Js基础知识(作用域、特殊函数---自调、回调、作为值的函数)
15.作用域 概念: 规定变量或函数的可被访问的范围和生命周期 分类: 全局作用域 -就是指当前整个页面环境: 局部作用域(函数作用域) -就是指某个函数内部环境 l 变量的作用域 全局变量 - 定义 ...
- 读书笔记之《HTML5 与 CSS3 基础教程》
1· 读前预期 考虑到对于 Web 开发零基础,凡涉足一件未知的任务,最好先理清任务的逻辑结构,然后有目的地逐步学习.为实现我们的需求和设计,必须要学习前端.后端.服务器等一系列暂时陌生的知识,在此, ...