【HDU】【3139】



Find the hotel

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 397    Accepted Submission(s): 103


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 <p i, d i> for a hotel h i, where p i stands for the price and d i 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 h 1, if there is a hotel h i, 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 (p i, d i) 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
 

Recommend
lcy







#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <assert.h>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;


int N;
struct Node
{
	int x,y;
	bool operator<(const Node&node) const
	{
		if(x == node.x)
		{
			return y < node.y;
		}
		return x < node.x;

	}
};
const int maxn = 10010;
Node node[maxn];
Node ans[maxn];
int cnt;
int main()
{
	freopen("1.txt","r",stdin);
	while(scanf("%d",&N) != EOF)
	{
		memset(ans,0,sizeof(ans));
		memset(node,0,sizeof(node));
		cnt = 0;
		int x,y;
		int lpos = 0;
		int lval = 0x3f3f3f3f;
		int rpos = 0;
		int rval = 0x3f3f3f3f;
		for(int i=0;i<N;i++)
		{
			scanf("%d%d",&x,&y);
			node[i].x = x ;
			node[i].y = y;
			if(i == 0 || node[i].x < lval || node[i].x == lval && node[i].y < node[lpos].y)
			{
						lpos = i;
				lval = node[i].x;
			}
			if(i == 0 || node[i].y < rval || node[i].y == rval && node[i].x < node[rpos].x)
			{
				rpos = i;
				rval = node[i].y;
			}
		}
		for(int i=0;i<N;i++)
		{
			if(node[i].x <= node[rpos].x && node[i].y <= node[lpos].y)
			{
				ans[cnt ].x = node[i].x;
				ans[cnt ].y = node[i].y;
				cnt ++;
			}
		}
		sort(ans,ans+cnt);
		printf("%d\n",cnt);
		for(int i=0;i<cnt;i++)
		{
			printf("%d %d\n",ans[i].x,ans[i].y);
		}
	}

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值