zoj 3041 City Selection yy的题

City Selection Time Limit: 5 Seconds       Memory Limit: 32768 KB

The government decided to build some cities in a newly developping area. Now they had N different locations to select from, while there were M factories in this newly developping area.

The area was blowing northwest wind, so if we choose a location that located on the southeast quadrant of one of the factory (including the boundary), the fog from the factory would pollute the city heavily.

Now it's your job to choose all the city locations that will not get pollution by the factories.

Input

The first line of a input block contains the numbers NM (1 <= NM <= 200000). Line 2 ~ N + 1 will each contain two integers(xy) the location of a city. Line N + 2 ~ M + N + 1 will each contains two integers(xy) the location of a factory. The x and y co-ordinates of the locations will be between -1000000000 and 1000000000, inclusive. There're no more than 10 test cases in the input data.

Output

The first line of your output block should be an integer K represent the number of city locations which the government can choose from. The next K lines should contain the co-ordinates of the cities. The co-ordinates should be sorted in ascending order of x co-ordinates, and in case of tie, ascending order of y co-ordinates.

Sample Input

3 3
0 1
-2 2
1 3
-2 2
2 0
4 4

Sample Output

1
1 3


题意:输入n,m,  再输入n个城市坐标,在输入m个工厂的坐标。  因为吹西北风的缘故,在工厂的 东南方向会受到污染,包括正南方向 和正东方向,还有自己本身的点都是会收到污染的。 然后判断有几个城市不收污染,输出坐标。

做法:预处理m个工厂,从左到右,不断把点的 y 更新为包括自己以及左边所有点的最大值。  这样直接搜索城市 city的x 坐标最近的工厂就可以了。那个工厂的y就是最高的限制。

#include <stdio.h>
#include <string> 
#include <string.h>
#include <algorithm>
#include <map>
using namespace std;
struct build
{
	int x,y;
};
int cmp(build a,build b)
{
	if(a.x!=b.x)
	return a.x<b.x;
	return a.y>b.y;//////////////////////
}
int cmp2(build a,build b)
{
	if(a.x!=b.x)
	return a.x<b.x;
	return a.y<b.y;//////////////////////
}
int max__(int a,int b)
{
	return a>b?a:b;
}
build city[200010],fact[200010];
map<int ,int>my;
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF)
	//scanf("%d%d",&n,&m);
	{
		my.clear();
		for(int i=0;i<n;i++)
		{
			scanf("%d%d",&city[i].x,&city[i].y);
		}

		for(int i=0;i<m;i++)//gongchang
		{
			scanf("%d%d",&fact[i].x,&fact[i].y);
		}
		sort(fact,fact+m,cmp); 
		int maxx=fact[0].y;
		my[fact[0].x]=maxx;
		for(int i=1;i<m;i++)
		{
			if(fact[i].x!=fact[i-1].x)
				maxx=my[fact[i].x]=max__(fact[i].y,maxx);
		}
		
		int k=0;//cheng
		for(int i=0;i<n;i++)// keyongcheng
		{
			map<int,int>::iterator it=my.upper_bound(city[i].x);
			if(it==my.begin())
			{
				city[k].x=city[i].x;
				city[k++].y=city[i].y;
				continue;
			}
			it--;
			if((it->second)<city[i].y)
			{
				city[k].x=city[i].x;
				city[k++].y=city[i].y;
			}
		}

		printf("%d\n",k);
		sort(city,city+k,cmp2);
		for(int i=0;i<k;i++)
		{
			printf("%d %d\n",city[i].x,city[i].y);
		}

	}
	return 0;
}
 /*
 //up zhuyi begin
 city  fact
 3 3
0 1
-2 2
1 3
-2 2
2 0
4 4


3 1
1 2
2 2
2 1

1 1
*/






你可能感兴趣的:(ACM)