[poj]2783:Holiday Hotel

 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.


思路,将所有的hotel按距离排序,选择价格小于所有排在其前的hotel的

#include<stdio.h>
#include<vector>
#include<algorithm>

using namespace std;

struct Hotel
{
	int dist;
	int cost;
	bool operator <(const Hotel& h) const
	{
		if(dist==h.dist)
			return cost<h.cost;
		return dist<h.dist;
	}
};

int main()
{
	int N;
	while(scanf("%d",&N)&&N)
	{
		vector<Hotel> hotels(N);

		for(int i=0;i<N;i++)
			scanf("%d%d",&hotels[i].dist,&hotels[i].cost);
		
		sort(hotels.begin(),hotels.end());

		int minCost=100000;
		int ret=0;
		for(int i=0;i<N;i++)
		{
			if(hotels[i].cost<minCost)
			{
				ret++;
				minCost=hotels[i].cost;
			}
		}

		printf("%d\n",ret);
	}

	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值