Find the hotel

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 767    Accepted Submission(s): 263

Problem Description
  Summer again! Flynn is ready for another tour around. Since the tour would take three or more days, it is important to find a hotel that meets for a reasonable price and gets as near as possible! 
  But there are so many of them! Flynn gets tired to look for any. It’s your time now! Given the <pi, di> for a hotel hi, where pi stands for the price and di is the distance from the destination of this tour, you are going to find those hotels, that either with a lower price or lower distance. Consider hotel h1, if there is a hotel hi, with both lower price and lower distance, we would discard h1. To be more specific, you are going to find those hotels, where no other has both lower price and distance than it. And the comparison is strict.
 
Input
There are some cases. Process to the end of file.
Each case begin with N (1 <= N <= 10000), the number of the hotel.
The next N line gives the (pi, di) for the i-th hotel.
The number will be non-negative and less than 10000.
 
Output
First, output the number of the hotel you find, and from the next line, print them like the input( two numbers in one line). You should order them ascending first by price and break the same price by distance.
 
Sample Input
3
15 10
10 15
8 9
 
Sample Output
1
8 9
 
Author
ZSTU
 
Source
 
  • 对于二元组(p,d)找凸点
  • 和hdu5517类似,但是这道题的数据范围是1e5,用树状数组做是开不下来的
  • 但是这题可以用ST表RMQ来解决
  • 对于每一个询问(pi,di)我们找p值小于pi的二元组,看其中的最小d的值,如果di<d我们就把(pi,di)添加进最终答案
  • 对于特殊的,如果p0是p值中的最小值,那么所有的(p0,d)组合都可以添加进最终答案
  • 从这道题的思路来讲,其实hdu5517也可以用这道题的方法做,就不用纠结二维树状数组的问题了
 #include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long LL ;
typedef unsigned long long ULL ;
const int maxn = 1e5 + ;
const int inf = 0x3f3f3f3f ;
const int npos = - ;
const int mod = 1e9 + ;
const int mxx = + ;
const double eps = 1e- ;
const double PI = acos(-1.0) ; struct node{
int p, d;
};
node h[maxn];
int cmp(const node &l, const node &r){
if(l.p!=r.p)
return l.p<r.p;
else
return l.d<r.d;
}
int Lower_Bound(int l, int r, int x){
while(l<r){
int m=(l+r)>>;
if(h[m].p>=x)
r=m;
else
l=m+;
}
return l;
}
int n, u, v, fac[], st[maxn], cnt;
int dp[maxn][], pl, pr, id;
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
for(int i=;i<;i++)
fac[i]=(<<i);
while(~scanf("%d",&n)){
for(int i=;i<=n;i++){
scanf("%d %d",&h[i].p,&h[i].d);
dp[i][]=i;
}
sort(h+,h++n,cmp);
int k=(int)(log((double)n)/log(2.0));
for(int j=;j<=k;j++)
for(int i=;i+fac[j]-<=n;i++){
pl=dp[i][j-];
pr=dp[i+fac[j-]][j-];
if(h[pl].d<h[pr].d)
dp[i][j]=pl;
else
dp[i][j]=pr;
}
u=;
cnt=;
st[cnt++]=;
for(int i=;i<=n;i++){
v=Lower_Bound(,i,h[i].p)-;
if(u<=v){
k=(int)(log((double)v)/log(2.0));
pl=dp[u][k];
pr=dp[v-fac[k]+][k];
if(h[pl].d<h[pr].d)
id=pl;
else
id=pr;
if(!(h[id].d<h[i].d))
st[cnt++]=i;
}else{
st[cnt++]=i;
}
}
printf("%d\n",cnt);
for(int i=;i<cnt;i++)
printf("%d %d\n",h[st[i]].p,h[st[i]].d);
}
return ;
}

HDU_3193_Find the hotel的更多相关文章

  1. POJ 3667 Hotel(线段树 区间合并)

    Hotel 转载自:http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html [题目链接]Hotel [题目类型]线段树 ...

  2. ACM: Hotel 解题报告 - 线段树-区间合并

    Hotel Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description The ...

  3. HDU - Hotel

    Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and e ...

  4. 【POJ3667】Hotel

    Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and e ...

  5. POJ-2726-Holiday Hotel

    Holiday Hotel   Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8302   Accepted: 3249 D ...

  6. Method threw 'org.hibernate.exception.SQLGrammarException' exception. Cannot evaluate com.hotel.Object_$$_jvst485_15.toString()

    数据库字段和类Object属性不匹配,Method threw 'org.hibernate.exception.SQLGrammarException' exception. Cannot eval ...

  7. poj 3667 Hotel(线段树,区间合并)

    Hotel Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 10858Accepted: 4691 Description The ...

  8. [POJ3667]Hotel(线段树,区间合并)

    题目链接:http://poj.org/problem?id=3667 题意:有一个hotel有n间房子,现在有2种操作: 1 a,check in,表示入住.需要a间连续的房子.返回尽量靠左的房间编 ...

  9. 【BZOJ】【3522】【POI2014】Hotel

    暴力/树形DP 要求在树上找出等距三点,求方案数,那么用类似Free Tour2那样的合并方法,可以写出: f[i][j]表示以 i 为根的子树中,距离 i 为 j 的点有多少个: g[i][j]表示 ...

随机推荐

  1. MongoDB C Driver Building on Windows

    一.编译mongodb c driver: 需要先安装OpenSSL:(参见:http://bbs.aircheng.com/read-2222-1) 步骤:(MongoDB步) 1.下载Active ...

  2. java基础——Collections.sort的两种用法

    Collections是一个工具类,sort是其中的静态方法,是用来对List类型进行排序的,它有两种参数形式: public static <T extends Comparable<? ...

  3. 查询_修改SQL Server 2005中数据库文件存放路径

    1.查看当前的存放路径: select database_id,name,physical_name AS CurrentLocation,state_desc,size from sys.maste ...

  4. 各大IT公司 技术博客汇总

    来自:http://www.cnblogs.com/IT-Bear/p/3191423.html 腾讯系列(13)  阿里系列(18)  百度系列(3)  搜狐系列(3)  新浪系列(2)  360系 ...

  5. 关于直播学习笔记-005 nginx-rtmp、sewiseplayer

    1.视频采集推流及服务器端:nginx-rtmp-windows 2.视频播放段:sewiseplayer 3.双击nginx.exe运行nginx-rtmp-win32-master的nginx服务 ...

  6. 设置MySQL的字符编码

    前言 这里我已经将MySQL的数据库编码设置为UTF-8,所以下面现实的都是UTF-8. 设置MySQL数据库的编码方式有三种,分别是基于session会话的.基于全局gloable的.永久性改变的. ...

  7. UE4 Run On Server与Run on owning client

  8. linux--GCC用法

    1简介 2简单编译 2.1预处理 2.2编译为汇编代码(Compilation) 2.3汇编(Assembly) 2.4连接(Linking) 3多个程序文件的编译 4检错 5库文件连接 5.1编译成 ...

  9. C#中的抽象类与重写

    今天的我们学习了好多,最初上午学习了文件流的方法,老师告诉我们是选修,可能以后不怎么用吧,但是还是想学下,似乎用个小程序读写文件很快地节奏,所以有点小兴趣学习,明天我再看看啦!今天之后学习了多态,继承 ...

  10. Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器[摘抄]

    [文章作者:张宴 本文版本:v6.3 最后修改:2010.07.26 转载请注明原文链接:http://blog.s135.com/nginx_php_v6/] 前言:本文是我撰写的关于搭建“Ngin ...