题目传送门

 /*
题意:求邀请顺序使得去爬山的人最多,每个人有去的条件
贪心+优先队列:首先按照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的更多相关文章

  1. HDOJ 5360 Hiking 优先队列+贪心

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5360 题意: 大概的意思就是每个人有个人数接受范围$[l_i,r_i]$,现在你每次能从还未被选取的人 ...

  2. hihoCoder 1309:任务分配 贪心 优先队列

    #1309 : 任务分配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定 N 项任务的起至时间( S1, E1 ), ( S2, E2 ), ..., ( SN,  ...

  3. UVA 11134 - Fabled Rooks(贪心+优先队列)

    We would like to place  n  rooks, 1 ≤  n  ≤ 5000, on a  n×n  board subject to the following restrict ...

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

  5. HDU 6438 网络赛 Buy and Resell(贪心 + 优先队列)题解

    思路:维护一个递增队列,如果当天的w比队首大,那么我们给收益增加 w - q.top(),这里的意思可以理解为w对总收益的贡献而不是真正获利的具体数额,这样我们就能求出最大收益.注意一下,如果w对收益 ...

  6. [POJ1456]Supermarket(贪心 + 优先队列 || 并查集)

    传送门 1.贪心 + 优先队列 按照时间排序从前往后 很简单不多说 ——代码 #include <queue> #include <cstdio> #include <i ...

  7. Painting The Fence(贪心+优先队列)

    Painting The Fence(贪心+优先队列) 题目大意:给 m 种数字,一共 n 个,从前往后填,相同的数字最多 k 个在一起,输出构造方案,没有则输出"-1". 解题思 ...

  8. CF140C New Year Snowmen(贪心+优先队列)

    CF140C 贪心+优先队列 贪心策略:每次取出数量最多的三种球,合成一个答案,再把雪球数都-1再插回去,只要还剩下三种雪球就可以不断地合成 雪球数用优先队列维护 #include <bits/ ...

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

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

随机推荐

  1. Python基础之 一列表

    列表模块:listlen(list):列表元素个数max(list):列表元素最大值min(list):列表元素最小值list(seq):将元组转为列表list.append(obj):列表末尾添加新 ...

  2. [bzoj2287][poj Challenge]消失之物_背包dp_容斥原理

    消失之物 bzoj-2287 Poj Challenge 题目大意:给定$n$个物品,第$i$个物品的权值为$W_i$.记$Count(x,i)$为第$i$个物品不允许使用的情况下拿到重量为$x$的方 ...

  3. Thread.run方法是同步方法

    Thread.run方法是同步方法, 线程: package com.stono.thread.page005; public class MyThread extends Thread { @Ove ...

  4. sharepoint 訪问缩略图

    Sharepoint缩略图 简单介绍 Sharepoint2010中有专门的图片库,当你新建图片库后,向图片上传一部分图片.当你浏览这个库时显示一排排小图片.当点击一个图片时进入显示的是大图.不要简单 ...

  5. 2016/1/21 练习 创建 接口interface 应用implements 类class 并实例化调用

    package testinterface; public interface ICpu { //电压 public boolean dianya(); //控制 public void kongzh ...

  6. SQLyog普通版与SQLyog企业版对比分析

    这里,为什么要写这篇博客呢? 对于SQLyog普通版而言,只能复制到不同的数据库里,这样显得麻烦,当然,你也可以用语句来操作达到实现目的. 具体做法: MySQL复制旧表的结构及数据到新表 CREAT ...

  7. Ubuntu 安装Consolas字体

    下载 YaHei.Consolas https://code.google.com/p/uigroupcode/downloads/list 安装 1.创建文件夹 sudo mkdir -p /usr ...

  8. iOS方法重写

    在O-C中子类可以继承父类的方法 ,而不需要从新编写相同的方法,但是有有时候子类并不想原封不动的继承父类的方法,而且是想做一些修改,这就采用啦方法的重写,方法从写有叫做方法覆盖,若子类的中的方法与父类 ...

  9. textView设置按下和焦点改变时让字体颜色发生变化

    在res/color/text_color_selector.xml这个下编写: <?xml version="1.0" encoding="utf-8" ...

  10. [Codeforces 1037E] Trip

    [题目链接] http://codeforces.com/problemset/problem/1037/E [算法] 首先离线 , 将问题倒过来考虑 , 转化为 : 每次删除一条边 , 此时最多有多 ...