贪心+优先队列 HDOJ 5360 Hiking
/*
题意:求邀请顺序使得去爬山的人最多,每个人有去的条件
贪心+优先队列:首先按照l和r从小到大排序,每一次将当前人数相同的被邀请者入队,那么只要能当前人数比最多人数条件小,该人能 被邀请,而且不用考虑最少人数的条件。网上的写的比我简洁,学习了。
详细解释:http://blog.csdn.net/queuelovestack/article/details/47319361
*/
/************************************************
* Author :Running_Time
* Created Time :2015-8-6 14:51:47
* File Name :H.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
struct Node {
int l, r, id;
bool operator < (const Node &x) const {
return r > x.r;
}
}node[MAXN];
priority_queue<Node> Q;
bool vis[MAXN];
int ans[MAXN];
int n; bool cmp(Node x, Node y) {
if (x.l == y.l) return x.r < y.r;
return x.l < y.l;
} int main(void) { //HDOJ 5360 Hiking
int T; scanf ("%d", &T);
while (T--) {
scanf ("%d", &n);
for (int i=; i<=n; ++i) {
scanf ("%d", &node[i].l); node[i].id = i;
}
for (int i=; i<=n; ++i) {
scanf ("%d", &node[i].r);
}
sort (node+, node++n, cmp); if (node[].l != ) {
puts ("");
for (int i=; i<=n; ++i) printf ("%d%c", i, (i==n) ? '\n' : ' ');
continue;
}
memset (vis, false, sizeof (vis));
while (!Q.empty ()) Q.pop ();
int i = , p = ;
for (; i<=n && p==node[i].l; ++i) Q.push (node[i]);
while (!Q.empty ()) {
while (!Q.empty ()) {
if (p <= Q.top ().r) {
ans[++p] = Q.top ().id;
vis[ans[p]] = true; Q.pop (); break;
}
else Q.pop ();
}
for (; i<=n && p==node[i].l; ++i) Q.push (node[i]);
} printf ("%d\n", p);
printf ("%d", ans[]);
for (int i=; i<=p; ++i) {
printf (" %d", ans[i]);
}
for (int i=; i<=n; ++i) {
if (!vis[i]) printf (" %d", i);
}
puts ("");
} return ;
}
贪心+优先队列 HDOJ 5360 Hiking的更多相关文章
- HDOJ 5360 Hiking 优先队列+贪心
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5360 题意: 大概的意思就是每个人有个人数接受范围$[l_i,r_i]$,现在你每次能从还未被选取的人 ...
- hihoCoder 1309:任务分配 贪心 优先队列
#1309 : 任务分配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定 N 项任务的起至时间( S1, E1 ), ( S2, E2 ), ..., ( SN, ...
- UVA 11134 - Fabled Rooks(贪心+优先队列)
We would like to place n rooks, 1 ≤ n ≤ 5000, on a n×n board subject to the following restrict ...
- C. Playlist Educational Codeforces Round 62 (Rated for Div. 2) 贪心+优先队列
C. Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- HDU 6438 网络赛 Buy and Resell(贪心 + 优先队列)题解
思路:维护一个递增队列,如果当天的w比队首大,那么我们给收益增加 w - q.top(),这里的意思可以理解为w对总收益的贡献而不是真正获利的具体数额,这样我们就能求出最大收益.注意一下,如果w对收益 ...
- [POJ1456]Supermarket(贪心 + 优先队列 || 并查集)
传送门 1.贪心 + 优先队列 按照时间排序从前往后 很简单不多说 ——代码 #include <queue> #include <cstdio> #include <i ...
- Painting The Fence(贪心+优先队列)
Painting The Fence(贪心+优先队列) 题目大意:给 m 种数字,一共 n 个,从前往后填,相同的数字最多 k 个在一起,输出构造方案,没有则输出"-1". 解题思 ...
- CF140C New Year Snowmen(贪心+优先队列)
CF140C 贪心+优先队列 贪心策略:每次取出数量最多的三种球,合成一个答案,再把雪球数都-1再插回去,只要还剩下三种雪球就可以不断地合成 雪球数用优先队列维护 #include <bits/ ...
- 2015多校第6场 HDU 5360 Hiking 贪心,优先队列
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5360 题意:给定n个人,现在要邀请这些人去远足,但每个人同意邀请的条件是当前已经同意去远足的人数c必须 ...
随机推荐
- Linux下汇编语言学习笔记1 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- Linux下汇编语言学习笔记33 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- POJ 3279 Fliptile【枚举】
题意: 又是农夫和牛的故事...有m*n个黑白块,黑块的背面是白块,白块背面是黑块,一头牛踩一块,则这个块的上下左右的方块都会转动,问至少踩多少块,才会使所有块都变成白色? 分析: 还是开关问题,同样 ...
- UVALive7042(博弈论)
题意: Bob和Alice在有向图内玩游戏,n个顶点,m条边. 每人一颗棋子,初始位置分别是x,y. Bob先手,轮流操作,每次只能走一条有向边. 结束条件: 1.不能操作的人输 2.两个棋子重合Bo ...
- wget下载网络图片
wget http....... --no-check-certificate
- reactjs 视频教程
近期玩了一下react,感觉挺不错的,搜了一下没有看到什么视频教程,于是自己便录制了几个入门视频.希望能够帮到大家.已经上传土豆了,能够点击以下的链接查看. http://www.tudou.com/ ...
- MTK Camera驱动移植
对于MTK Camera驱动移植一般分为四部分: 1.硬件IO口配置: 2.Camera驱动移植: 3.上电时序. 4.改动i2c控制器: 硬件电路: 1.GPIO配置 打开 mediatek\dct ...
- linux网络结构体
一 链路层: (1)局域网(以太网ethernet): *struct eth_header:以太网头部. (ethernet/eth.c) *struct net_device:每一个网络设备都用这 ...
- cocos2dx-3.0(21) 移植android平台 说多了都是泪
----我的生活,我的点点滴滴! ! 网上3.0的教程真心少.能够说没有吧,大多都是2.x 或者 3.0測试版之类的,因为我心大,没有照着2.x去搞,后来搞完后总结了一下,发觉事实上3.0的移植and ...
- Datagridview CurrentRow.Index
int index = dataGridView1.CurrentRow.Index; //获取当前选择行引导 string str = dataGridView1.Rows[index].Cell ...