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 ...
随机推荐
- 函数strcpy的实现
strcpy函数的百科中给出了各种情况的详细说明,这里,仅给出一些注意事项: 1.strcpy的函数原型是: /* dest(destination)为目标字符串,src(source)为原字符串*/ ...
- 添加网站标题logo
如何在标题栏title前添加网站logo? 第一种方法:据说在网站根目录下放着我们的ico型logo,命名为favicon.ico,浏览器会自动去找到并显示.试了试,在firefox23和ie8下都没 ...
- 【计数】【UVA11401】 Triangle Counting
传送门 Description 把1……n这n个数中任取3个数,求能组成一个三角形的方案个数 Input 多组数据,对于每组数据,包括: 一行一个数i,代表前i个数. 输入结束标识为i<3. O ...
- Codeforces Round #330 (Div. 2) B. Pasha and Phone
B. Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- POJ3164:Command Network(有向图的最小生成树)
Command Network Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 20766 Accepted: 5920 ...
- Mybatis中什么时候应该声明jdbcType
转:http://blog.csdn.net/l799069596/article/details/52052777 疑问来自于,有时候Mapper.xml中 pid = #{pid,jdbcType ...
- [zabbix]zabbix2.0apt源安装
http://www.sysadminworld.com/2013/install-zabbix-2-on-ubuntu-12-04-precise/
- STM32之窗口看门狗
1.有个7位递减计数器(WWDG->CR),就这个计数器和窗口计数器(WWDG->CFR)决定什么时候喂狗.狗喂早了,复位——“早”体现在 计数器值(tr)>窗口值(wr),也就是计 ...
- Android LayoutInflater深度解析
1. 题外话 相信大家对LayoutInflate都不陌生,特别在ListView的Adapter的getView方法中基本都会出现,使用inflate方法去加载一个布局,用于ListView的每个I ...
- Base class does not contain a constructor that takes '0' argument
刚刚在写一段直播室网站中的一段程序遇,突然遇到一个错误,如下 'TVLLKBLL.BaseClass' does not contain a constructor that takes 0 argu ...