2018_2_8_Holiday Hotel_结构体排序

12 篇文章 0 订阅

Language:
Holiday Hotel
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 8532 Accepted: 3339

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:
  1. Any hotel which is closer to the seashore than M will be more expensive than M.
  2. 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

Beijing 2005
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string> 
#include<cctype>
#include<vector>
#include<algorithm> 
#include<map>
#include<set>
using namespace std;

const int N=1e4+10;

struct AA{
	int d;
	int c;
	void input(){
		scanf("%d%d",&d,&c);
	}
}a[N];
int n;

bool cmp(AA a,AA b){
	if(a.d==b.d)return a.c<b.c;
	return a.d<b.d;
}

int main(){
	while(scanf("%d",&n),n){
		for(int i=0;i<n;i++)
		a[i].input();
		sort(a,a+n,cmp);
		int ans=1,p=0;
		for(int i=1;i<n;i++)
		if(a[i].c<a[p].c){
			ans++;p=i;
		}
		printf("%d\n",ans);
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值