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也可以用这道题的方法做,就不用纠结二维树状数组的问题了
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <climits>
  7. #include <cmath>
  8. #include <vector>
  9. #include <queue>
  10. #include <stack>
  11. #include <set>
  12. #include <map>
  13. using namespace std;
  14. typedef long long LL ;
  15. typedef unsigned long long ULL ;
  16. const int maxn = 1e5 + ;
  17. const int inf = 0x3f3f3f3f ;
  18. const int npos = - ;
  19. const int mod = 1e9 + ;
  20. const int mxx = + ;
  21. const double eps = 1e- ;
  22. const double PI = acos(-1.0) ;
  23.  
  24. struct node{
  25. int p, d;
  26. };
  27. node h[maxn];
  28. int cmp(const node &l, const node &r){
  29. if(l.p!=r.p)
  30. return l.p<r.p;
  31. else
  32. return l.d<r.d;
  33. }
  34. int Lower_Bound(int l, int r, int x){
  35. while(l<r){
  36. int m=(l+r)>>;
  37. if(h[m].p>=x)
  38. r=m;
  39. else
  40. l=m+;
  41. }
  42. return l;
  43. }
  44. int n, u, v, fac[], st[maxn], cnt;
  45. int dp[maxn][], pl, pr, id;
  46. int main(){
  47. // freopen("in.txt","r",stdin);
  48. // freopen("out.txt","w",stdout);
  49. for(int i=;i<;i++)
  50. fac[i]=(<<i);
  51. while(~scanf("%d",&n)){
  52. for(int i=;i<=n;i++){
  53. scanf("%d %d",&h[i].p,&h[i].d);
  54. dp[i][]=i;
  55. }
  56. sort(h+,h++n,cmp);
  57. int k=(int)(log((double)n)/log(2.0));
  58. for(int j=;j<=k;j++)
  59. for(int i=;i+fac[j]-<=n;i++){
  60. pl=dp[i][j-];
  61. pr=dp[i+fac[j-]][j-];
  62. if(h[pl].d<h[pr].d)
  63. dp[i][j]=pl;
  64. else
  65. dp[i][j]=pr;
  66. }
  67. u=;
  68. cnt=;
  69. st[cnt++]=;
  70. for(int i=;i<=n;i++){
  71. v=Lower_Bound(,i,h[i].p)-;
  72. if(u<=v){
  73. k=(int)(log((double)v)/log(2.0));
  74. pl=dp[u][k];
  75. pr=dp[v-fac[k]+][k];
  76. if(h[pl].d<h[pr].d)
  77. id=pl;
  78. else
  79. id=pr;
  80. if(!(h[id].d<h[i].d))
  81. st[cnt++]=i;
  82. }else{
  83. st[cnt++]=i;
  84. }
  85. }
  86. printf("%d\n",cnt);
  87. for(int i=;i<cnt;i++)
  88. printf("%d %d\n",h[st[i]].p,h[st[i]].d);
  89. }
  90. return ;
  91. }

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. vector、map删除当前记录

    map<string, string> sMap; map<string, string>::iterator iter; for(iter = sMap.begin();it ...

  2. python中使用@property

    class Student(object): @property def score(self): return self._score @score.setter def score(self, v ...

  3. CSS导入使用及引用的两种方法

    方法一<link rel="stylesheet" type="text/css" href="test.css"> 方法二&l ...

  4. jpa动态分页查找

    https://my.oschina.net/buwei/blog/172402 http://www.cnblogs.com/derry9005/p/6282571.html http://2560 ...

  5. Linux配置防火墙,开启80port、3306port 可能会遇到的小问题

     vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(同意80端口通 ...

  6. hadoop本地测试命令

    http://www.cnblogs.com/shishanyuan/p/4190403.html if have assign the /etc/profile: hadoop jar /usr/l ...

  7. AssetBundle中Unload()方法的作用

    AssetBundle.Unload(false)的作用: 官网的解释是这样的: When unloadAllLoadedObjects is false, compressed file data ...

  8. htaccess文件中RewriteRule 规则参数介绍

    .htaccess 文件 <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d Rew ...

  9. Oracle Apex 有用笔记系列 2 - 文件上传管理

    1. 页面设计 页面A有若干region, 当中一个region用于文件列表管理(包含显示,下载.删除).如图A. 在页面A有一button,点击它会调用页面B,页面B负责文件上传.如图B. 图A 图 ...

  10. Dubbo(四) -- telnet命令

    一.telnet的作用 当dubbo服务(即生产者)发布之后,我们可以通过telnet命令来来进行调试和管理,以及跟踪服务调用的次数. 注意:2.0.5以上版本服务提供端口支持telnet命令,协议一 ...