HDU_3193_Find the hotel
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
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.
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.
15 10
10 15
8 9
8 9
- 对于二元组(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的更多相关文章
- POJ 3667 Hotel(线段树 区间合并)
Hotel 转载自:http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html [题目链接]Hotel [题目类型]线段树 ...
- ACM: Hotel 解题报告 - 线段树-区间合并
Hotel Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Description The ...
- HDU - Hotel
Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and e ...
- 【POJ3667】Hotel
Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and e ...
- POJ-2726-Holiday Hotel
Holiday Hotel Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8302 Accepted: 3249 D ...
- 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 ...
- poj 3667 Hotel(线段树,区间合并)
Hotel Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 10858Accepted: 4691 Description The ...
- [POJ3667]Hotel(线段树,区间合并)
题目链接:http://poj.org/problem?id=3667 题意:有一个hotel有n间房子,现在有2种操作: 1 a,check in,表示入住.需要a间连续的房子.返回尽量靠左的房间编 ...
- 【BZOJ】【3522】【POI2014】Hotel
暴力/树形DP 要求在树上找出等距三点,求方案数,那么用类似Free Tour2那样的合并方法,可以写出: f[i][j]表示以 i 为根的子树中,距离 i 为 j 的点有多少个: g[i][j]表示 ...
随机推荐
- Xshell和SecureCRT等SSH下使用Tmux及Byobu(解决Byobu被statusline信息面板刷屏问题)
Vim的vsplit用得爽吧!多命令行模式,同样让你爽得不蛋疼! 下面介绍一下两个终端多控制台软件:Tmux 和 Byobu!本文还是以Xshell为主进行介绍! --------------Tmux ...
- linux -- Ubuntu下安装和配置Apache2
在Ubuntu中安装apache 安装指令:sudo apt-get install apache2 启动和停止apache的文件是:/etc/init.d/apache2 启动命令:sudo apa ...
- CentOS Linux 下安装Samba
一.Samba简介: Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成.Linux中搭建环境有几个需要使用的软件包: (1)samba-client:这个 ...
- php常见的坑
10.filesize缓存的问题 PHP的filesize居然会缓存(当然还有不少,这里仅用filesize举例,其它会缓存的函数,以官方文档为准)线上代码经常随机出各种问题,排查了1个月,线上加各种 ...
- Unity教程之-基于行为树与状态机的游戏AI
AI.我们的第一印象可能是机器人,现在主要说在游戏中的应用.关于AI的相关文章我们在前面也提到过,详细请戳这现代的计算机游戏中已经大量融入了AI元素,平时我们进行游戏时产生的交互都是由AI来完成的.比 ...
- java jdk-awt.font在centos上中文乱码的问题, 安装中文字体
有需求生成一个二维码,并且有一段文本说明,但是使用awt.font来生成中文时,一直存在乱码的问题.网上的解决办法有几种,但是在centos上亲测有用的就是如下的方法. Java代码如下:new ja ...
- KAFKA安装+配置详解+常用操作+监控
http://blog.csdn.net/hadas_wang/article/details/50056381 http://qiyishi.blog.51cto.com/5731577/18575 ...
- 5、Cocos2dx 3.0游戏开发找小三之測试例子简单介绍及小结
重开发人员的劳动成果.转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/27186557 測试例子简单介绍 Cocos2d-x ...
- C++第15周(春)项目3 - OOP版电子词典(二)
课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [项目3-OOP版电子词典](本程序须要的相关 ...
- 超全面的JavaWeb笔记day12<Jsp&JavaBean&El表达式>
1.JSP三大指令 page include taglib 2.9个内置对象 out page pageContext request response session application exc ...