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

Problem Description
There are n soda conveniently labeled by 1,2,…,n. beta, their best friends, wants to invite some soda to go hiking. The i-th soda will go hiking if the total number of soda that go hiking except him is no less than li and no larger than ri. beta will follow the rules below to invite soda one by one:
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.

 
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

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.

 
Output
For each test case, output the maximum number of soda. Then in the second line output a permutation of 1,2,…,n denoting the invitation order. If there are multiple solutions, print any of them.
 
Sample Input

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

 
Sample Output
7
1 7 6 5 2 4 3 8
8
4 6 3 1 2 5 8 7
7
3 6 7 1 5 2 8 4
0
1 2 3 4 5 6 7 8
 
Source
/**
题意:现在有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的更多相关文章

  1. HDU 5360 (贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5360 题意:告诉你n个区间[ l[i],r[i] ],然后让你排序,必须左区间不大于它前边的总区间个数 ...

  2. 2015多校第6场 HDU 5360 Hiking 贪心,优先队列

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5360 题意:给定n个人,现在要邀请这些人去远足,但每个人同意邀请的条件是当前已经同意去远足的人数c必须 ...

  3. hdu 5360 Hiking(优先队列+贪心)

    题目:http://acm.hdu.edu.cn/showproblem.php? pid=5360 题意:beta有n个朋友,beta要邀请他的朋友go hiking,已知每一个朋友的理想人数[L, ...

  4. HDU 5360 Hiking 登山 (优先队列,排序)

    题意: 有n个人可供邀请去hiking,但是他们很有个性,每个人都有个预期的人数上下限[Li,Ri],只有当前确定会去的人数在这个区间内他才肯去.一旦他答应了,无论人数怎样变更,他都不会反悔.问最多能 ...

  5. HDU 5360 Hiking (贪心)

    题意:邀请 n 参加聚会,如果在邀请第 i 个人之前,已经成功邀请了 x 个人,并且 li <= x <= ri,那么第 i 人才会去,问你怎么排列使得邀请的人最多. 析:对于所有的人,按 ...

  6. 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 ...

  7. HDU 5360——Hiking——————【贪心+优先队列】

    Hiking Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

  8. HDU 5360 Hiking(优先队列)

    Hiking Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total S ...

  9. HDU 5360 【优先队列+贪心】

    题意: 给定N个无序区间. 对合法区间的定义是: 在这个区间之前已经选出了至少l个合法区间,最多选出了r个合法区间.则该区间为合法区间. 输出最多能挑选出多少个合法区间,并输出合法区间的数量. 思路: ...

  10. 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 ...

随机推荐

  1. [POI2014]DOO-Around the world

    通过几年的努力,Byteasar最终拿到了飞行员驾驶证.为了庆祝这一事实,他打算买一架飞机并且绕Byteotia星球赤道飞行一圈.但不幸的是赤道非常长所以需要中途加几次油.现在已知赤道上面所有飞机场, ...

  2. 【DP】【P1941】【NOIP2014D1T3】飞扬的小鸟

    传送门 Description Flappy Bird是一款风靡一时的休闲手机游戏.玩家需要不断控制点击手机屏幕的频率来调节小鸟的飞行高度,让小鸟顺利通过画面右方的管道缝隙.如果小鸟一不小心撞到了水管 ...

  3. JavaScript身份证号码有效性验证

    最近需要对身份证合法性进行验证,实名验证是不指望了,不过原来的验证规则太过简单,只是简单的验证了身份证长度,现在业务需要加强下身份证验证规则,网上找到了不少资料,不过都不合偶的心意,无奈只好直接写一个 ...

  4. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A B 水 搜索

    A. Oath of the Night's Watch time limit per test 2 seconds memory limit per test 256 megabytes input ...

  5. C++智能指针 unique_ptr

    C++智能指针 unique_ptr unique_ptr 独占所指向的对象, 同一时刻只能有一个 unique_ptr 指向给定对象(通过禁止拷贝语义, 只有移动语义来实现), 定义于 memory ...

  6. [解决] User [dr.who] is not authorized to view the logs for application

    在hadoop集群启用权限控制后,发现job运行日志的ui访问不了, User [dr.who] is not authorized to view the logs for application ...

  7. vijos 1426 背包+hash

    背景 北京奥运会开幕了,这是中国人的骄傲和自豪,中国健儿在运动场上已经创造了一个又一个辉煌,super pig也不例外……………… 描述 虽然兴奋剂是奥运会及其他重要比赛的禁药,是禁止服用的.但是运动 ...

  8. django中处理表单的经典流程

    def form_process_view(request): if request.method == 'POST': # 请求为 POST,利用用户提交的数据构造一个绑定了数据的表单 form = ...

  9. bzoj 1912 tree_dp

    这道题我们加一条路可以减少的代价为这条路两端点到lca的路径的长度,相当于一条链,那么如果加了两条链的话,这两条链重复的部分还是要走两遍,反而对答案没有了贡献(其实这个可以由任意两条链都可以看成两条不 ...

  10. SQL SERVER 创建远程数据库链接 mysql oracle sqlserver

    遇到的坑 在连接Oracle时,因为服务器为10g 32位版本,然后在本地安装了32为10g客户端,然后一直报错[7302.7303],后来下载了12c 64位版本,安装成功后,问题解决 原因:mss ...