Holiday Hotel
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 7757 | Accepted: 3040 |
Description
Mr. and Mrs. Smith are going to the seaside for their holiday. Before they start off, they need to choose a hotel. They got a list of hotels from the Internet, and want to choose some candidate hotels which are cheap and close to the seashore. A candidate hotel M meets two requirements:
- Any hotel which is closer to the seashore than M will be more expensive than M.
- Any hotel which is cheaper than M will be farther away from the seashore than M.
Input
There are several test cases. The first line of each test case is an integer N (1 <= N <= 10000), which is the number of hotels. Each of the following N lines describes a hotel, containing two integers D and C (1 <= D, C <= 10000). D means the distance from the hotel to the seashore, and C means the cost of staying in the hotel. You can assume that there are no two hotels with the same D and C. A test case with N = 0 ends the input, and should not be processed.
Output
For each test case, you should output one line containing an integer, which is the number of all the candidate hotels.
Sample Input
5 300 100 100 300 400 200 200 400 100 500 0
Sample Output
2
Source
水题,刚刚看时头晕了,。。。。。。
把价钱与距离看作是点的x,y坐标,对点做横竖两个轴,左下方(包括轴上)没其他点,那么这个点就符合要求了!
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
struct node
{
int m,l;
}p[10005];
bool cmp(node a,node b)
{
if(a.m==b.m)return a.l<b.l;
else return a.m<b.m;
}
int main()
{
while(scanf("%d",&n)&&n)
{
for(int i=0;i<n;i++)scanf("%d%d",&p[i].l,&p[i].m);
sort(p,p+n,cmp);
int key=1000000,ans=0;
for(int i=0;i<n;i++)
{
if(p[i].l<key)
{
ans++;
key=p[i].l;
}
}
cout<<ans<<endl;
}
return 0;
}