HDU_3193_Find the hotel, hdu_3193_findhotel

Source: Internet
Author: User

HDU_3193_Find the hotel, hdu_3193_findhotel
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 wocould 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 lost 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 wowould 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.

 

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

 

OutputFirst, output the number of the hotel you find, and from the next line, print them like the input (two numbers in one line ). you shoshould order them ascending first by price and break the same price by distance.

 

Sample Input315 1010 158 9

 

Sample Output18 9

 

AuthorZSTU

 

SourceHDU 2009-12 Programming Contest
  • Find convex points for Binary groups (p, d)
  • Similar to hdu5517, but the data range of this question is 1e5, which cannot be implemented using a tree array.
  • However, this problem can be solved using the ST table RMQ.
  • For each query (pi, di), we look for a binary group with a P value less than pi to see the minimum d value. If di <d, we set (pi, di) add to final answer
  • For special, if p0 is the minimum value in the P value, all (p0, d) combinations can be added to the final answer.
  • In terms of the idea of this question, in fact, hdu5517 can also be used to solve the problem, so there is no need to tangle with the problem of two-dimensional tree arrays.

 

 

 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 + 10   ;17 const int    inf  = 0x3f3f3f3f ;18 const int    npos = -1         ;19 const int    mod  = 1e9 + 7    ;20 const int    mxx  = 100 + 5    ;21 const double eps  = 1e-6       ;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     else32         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)>>1;37         if(h[m].p>=x)38             r=m;39         else40             l=m+1;41     }42     return l;43 }44 int n, u, v, fac[30], st[maxn], cnt;45 int dp[maxn][30], pl, pr, id;46 int main(){47     // freopen("in.txt","r",stdin);48     // freopen("out.txt","w",stdout);49     for(int i=0;i<30;i++)50         fac[i]=(1<<i);51     while(~scanf("%d",&n)){52         for(int i=1;i<=n;i++){53             scanf("%d %d",&h[i].p,&h[i].d);54             dp[i][0]=i;55         }56         sort(h+1,h+1+n,cmp);57         int k=(int)(log((double)n)/log(2.0));58         for(int j=1;j<=k;j++)59             for(int i=1;i+fac[j]-1<=n;i++){60                 pl=dp[i][j-1];61                 pr=dp[i+fac[j-1]][j-1];62                 if(h[pl].d

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.