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 ...
随机推荐
- windows FTP自动下载脚本
新建ftp.dat文件,内容如下 open xxx.xxx.xxx.xxxusernamepasswordcd lcd x:\filesbinaryhashmget *.*bye 新建run.b ...
- CF787A - The Monster
/* CF787A - The Monster http://codeforces.com/contest/787/problem/A 数学 扩展欧几里得 注意x或y为0的时候要特判 并且结果要大于b ...
- POJ 2132
我早上调了一个早上,下午才发现把e=edge[e].next写成edge[e].next了... 这题直接DFS,一个剪枝是,当当前的最大质因数是最小公倍数的因数时,不用搜索 #include < ...
- POJ 3050 Hopscotch 水~
http://poj.org/problem?id=3050 题目大意: 在一个5*5的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始 ...
- sedna载入xml文件
如果有一个xml文件a.xml.须要把它载入到sedna数据库xml_db里. sedna是通过se_term把xml载入到数据库的.有两种方法: 1.通过se_term的-query參数. se_t ...
- HTML iframe 和 frameset 的区别
转自:http://www.cnblogs.com/polk6/archive/2013/05/24/3097430.html HTML iframe 和 frameset 的区别 iframe 和 ...
- 7. Reverse Integer[E]整数反转
题目 Given a 32-bit signed integer, reverse digits of an integer. Example1: x = 123, return 321 Exampl ...
- Mac 安装cmake小问题
今天用 brew install cmake. ==> Downloading https://homebrew.bintray.com/bottles/cmake-3.9.6.sierra.b ...
- JQuery学习系列篇(一)
jQuery是一套Javascript脚本库:注意jQuery是脚本库, 而不是脚本框架. "库"不等于"框架", 比如"System程序集" ...
- week4_notebooke1
今日大纲:01名称空间,作用域,取值顺序02函数的嵌套03内置函数 globals() locals()04关键字global nonlocal05函数名的应用06闭包07装饰器初识08装饰器进阶 注 ...