HDU-5360
Hiking
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 76 Accepted Submission(s): 42
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.
4
8
4 1 3 2 2 1 0 3
5 3 6 4 2 1 7 6
8
3 3 2 0 5 0 3 6
4 5 2 7 7 6 7 6
8
2 2 3 3 3 0 0 2
7 4 3 6 3 2 2 5
8
5 6 5 3 3 1 2 4
6 7 7 6 5 4 3 5
/**
题意:现在有n个人,然后soda想要n个人尽可能多的去野营,每个人去野营是要在soda询问他时,
他所知道的去的人数大于等于L[i] 小于等于R[i] 然后问哪种询问顺序,可以使去的人数最多
做法:结构体 + 优先队列
首先第一个人的L[i]必须是0,然后在同样的下标为L[i]的进队列,
然后队列中的元素按照r[i]的大小排序,使得R[i]最小的优先
**/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
#define maxn 100000 + 10
int vis[maxn];
int mmap[maxn];
struct Node
{
int l;
int r;
int id;
bool operator <(const Node &a)const
{
return r > a.r;
}
Node()
{
l = ;
r = ;
id = ;
}
} node[maxn];
int cmp(Node a,Node b)
{
if(a.l != b.l) return a.l < b.l;
return a.r , b.r;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i=; i<n; i++)
{
scanf("%d",&node[i].l);
}
for(int i=; i<n; i++)
{
scanf("%d",&node[i].r);
node[i].id = i+;
}
sort(node,node+n,cmp);
memset(mmap,,sizeof(mmap));
priority_queue<Node>que;
while(!que.empty()) que.pop();
int sum = ;
int tt = ;
int tt1 = n-;
if(node[].l != )
{
printf("0\n");
for(int i=; i<n; i++)
{
printf("%d",i+);
if(i!= n-) printf(" ");
else printf("\n");
}
continue;
}
que.push(node[]);
Node now,tmp;
int i = ;
while(!que.empty())
{
for(; node[i].l == sum&&i<n; i++)
que.push(node[i]);
while(!que.empty())
{
if(que.top().r >= sum)
{
int tx = que.top().id;
mmap[tt++] = tx;
sum++;
que.pop();
break;
}
else
mmap[tt1--] = que.top().id;
que.pop();
}
for(;node[i].l == sum&&i<n;i++)
que.push(node[i]);
}
for(;i<n;i++)
mmap[tt1--] = node[i].id;
printf("%d\n",tt);
for(i=;i<n;i++)
{
printf("%d",mmap[i]);
if(i!= n-) printf(" ");
else printf("\n");
}
}
return ;
}
HDU-5360的更多相关文章
- HDU 5360 (贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5360 题意:告诉你n个区间[ l[i],r[i] ],然后让你排序,必须左区间不大于它前边的总区间个数 ...
- 2015多校第6场 HDU 5360 Hiking 贪心,优先队列
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5360 题意:给定n个人,现在要邀请这些人去远足,但每个人同意邀请的条件是当前已经同意去远足的人数c必须 ...
- hdu 5360 Hiking(优先队列+贪心)
题目:http://acm.hdu.edu.cn/showproblem.php? pid=5360 题意:beta有n个朋友,beta要邀请他的朋友go hiking,已知每一个朋友的理想人数[L, ...
- HDU 5360 Hiking 登山 (优先队列,排序)
题意: 有n个人可供邀请去hiking,但是他们很有个性,每个人都有个预期的人数上下限[Li,Ri],只有当前确定会去的人数在这个区间内他才肯去.一旦他答应了,无论人数怎样变更,他都不会反悔.问最多能 ...
- HDU 5360 Hiking (贪心)
题意:邀请 n 参加聚会,如果在邀请第 i 个人之前,已经成功邀请了 x 个人,并且 li <= x <= ri,那么第 i 人才会去,问你怎么排列使得邀请的人最多. 析:对于所有的人,按 ...
- 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 ...
- HDU 5360——Hiking——————【贪心+优先队列】
Hiking Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
- HDU 5360 Hiking(优先队列)
Hiking Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total S ...
- HDU 5360 【优先队列+贪心】
题意: 给定N个无序区间. 对合法区间的定义是: 在这个区间之前已经选出了至少l个合法区间,最多选出了r个合法区间.则该区间为合法区间. 输出最多能挑选出多少个合法区间,并输出合法区间的数量. 思路: ...
- 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 Su ...
随机推荐
- BZOJ1047:[HAOI2007]理想的正方形——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1047 https://www.luogu.org/problemnew/show/P2216#sub ...
- BZOJ2002:[HNOI2010]弹飞绵羊——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=2002 https://www.luogu.org/problemnew/show/P3203 某天, ...
- AOJ. 数组训练.2016-11-17
A题 #include <stdio.h> #include <stdlib.h> #define max 1000 __int64 a[max] = {0,1,1}; int ...
- Matrix-Tree定理题表
矩阵树这个东西……并不懂什么基尔霍夫矩阵……背了一下结论……(顺便用这个东西加强了一下矩阵)(打板子的时候还是该取负取负,因为不取负才有可能是负数,最后答案一定是正数???(ryf说一定是这样))bz ...
- 拼接sql语句参数绑定
/** * 事务封装方法 * @access public * @param array $sqls 要执行的sql数组或语句 * @return boolean */ public function ...
- mysql五补充部分:SQL逻辑查询语句执行顺序
一 SELECT语句关键字的定义顺序 SELECT DISTINCT <select_list> FROM <left_table> <join_type> JOI ...
- ACE的安装
转载于:http://www.cnblogs.com/TianFang/archive/2006/12/03/580714.html ACE的安装是一件比较麻烦的事情,这里简单的记录了我在VS2005 ...
- Intervals ZOJ - 3953 (区间贪心)
Chiaki has n intervals and the i-th of them is [li, ri]. She wants to delete some intervals so that ...
- Javascript基本代码
简单的了解了javascript 的基本代码,感觉和c#中的语句差不多. <!DOCTYPE html> <html xmlns="http://www.w3.org/19 ...
- redis 查看所有键值
zb@zb-computer:/home/wwwroot/default/lion/Admin$ /usr/local/redis/bin/redis-cli 127.0.0.1:6379> k ...