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 ... 
随机推荐
- HDU5115:Dire Wolf——题解+翻译
			http://acm.hdu.edu.cn/showproblem.php?pid=5115 题目大意:给n匹狼,每一次攻击可以秒杀一匹狼,但同时会受到这匹狼的a攻击和它相邻两只狼的b攻击. 给定a, ... 
- [bzoj] 2002 弹飞绵羊 || LCT
			原题 简单的LCT练习题. 我们发现对于一个位置x,他只能跳到位置x+k,也就是唯一的父亲去.加入我们将弹飞的绵羊定义为跳到了n+1,那么这就形成了一棵树.而因为要修改k,所以这颗树是动态连边的,那么 ... 
- 洛谷 P4964 绫小路的特别考试 解题报告
			P4964 绫小路的特别考试 题目背景 这世界上「胜利」便是一切.无关乎过程. 要付出多少牺牲都无所谓.只要最后我「胜出」那就行了. 题目描述 一场新的特别考试来临了,这次的考试内容是(wan e d ... 
- AOJ.562 寻找罗恩和赫敏
			寻找罗恩和赫敏 考察点 水题 Time Mem Len Lang 0 492KB 0.42K G++ 题意分析 计算1/C(n,2)的值 代码总览 /* Title:AOJ.562 Author:pe ... 
- 两年Java的面试经验
			前言:从过年前就萌生出要跳槽的想法,到过年来公司从3月初提出离职到23号正式离职,上班的时间也出去面试过几家公司,后来总觉的在职找工作总是得请假,便决心离职后找工作.到4月10号找到了一家互联网公司成 ... 
- Matrix.(POJ-2155)(树状数组)
			题目是让每次对一个子矩阵进行翻转(0变1,1变0), 然后有多次询问,询问某个点是0还是1 这题可以用二维的树状数组来解决,考虑传统的树状数组是改变某个点,然后查询某一段, 而这个题是改变某一段,查询 ... 
- 分割png图片
			/*** * 分割图片 */public function cut_img(){ $filename = 'site_upload/form_file_forinput/20180313/201803 ... 
- JS如何判断是不是iphoneX
			function isIphoneX(){ return /iphone/gi.test(navigator.userAgent) && (screen.height == 812 & ... 
- maven插件理解
			maven插件的主要功能是对用到的jar包进行管理,jar包先从本地仓库中获取,如果没有找到,则从远处中央仓库下载(需要联外网).本地仓库中的jar包可供所有maven工程使用,属于公共模块. mav ... 
- Hibernate入门(4)- Hibernate数据操作
			Hibernate加载数据 Session.get(Class clazz, Serializable id) clazz:需要加载对象的类,例如:User.class id:查询条件(实现了序列化接 ... 
