zoj 3041 City Selection(数学啊)

题目链接:?problemId=2039

The government decided to build some cities in a newly developping area. Now they hadN 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 N, M (1 <=N, M <= 200000). Line 2 ~ N + 1 will each contain two integers(x,y) the location of a city. Line N + 2 ~ M + N + 1 will each contains two integers(x,y) 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 nextK 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 30 1-2 21 3-2 22 04 4

Sample Output

11 3

题意:

给出一些城市和工厂的位置,城市不能在工厂的东南方向,求能安放的城市的个数个位置!

ps:

首先按照城市和工厂的x坐标从小达到排序,再寻找每个城市前面是否有y坐标比当前城市大的,,如果有则此处不能安放城市

注意:案例有城市和工厂在同一位置的情况!

代码如下:

#include <cstdio>#include <cmath>#include <iostream>#include <algorithm>using namespace std;#define maxn 500000#define INF 0x3f3f3f3fstruct node{int x, y;int flag;} a[maxn];bool cmp(node a, node b)//排序{if(a.x == b.x){return a.y < b.y;}return a.x < b.x;}int main(){int n, m;int x1[maxn], y1[maxn];int b[maxn];while(~scanf("%d%d",&n,&m)){int num = 0;for(int i = 0; i < n; i++){scanf("%d%d",&a[i].x,&a[i].y);a[i].flag = 1;//城市}for(int i = n; i < n + m; i++){scanf("%d%d",&a[i].x,&a[i].y);a[i].flag = 2;//工厂}sort(a, a+n+m, cmp);int maxx = -INF;//最大值for(int i = 0; i < n + m; i++){if(a[i].flag == 2 && maxx < a[i].y){maxx = a[i].y;//找到最大的y坐标}if(a[i].flag == 1 && a[i].y > maxx){if(a[i].x==a[i+1].x && a[i].y==a[i+1].y)//坐标相同continue;if(a[i].x==a[i-1].x && a[i].y==a[i-1].y)//坐标相同continue;b[num] = i;num++;}}printf("%d\n",num);//printf("%d %d",a[b[0]].x,a[b[0]].y);for(int i = 0; i < num; i++){printf("%d %d\n",a[b[i]].x,a[b[i]].y);}}return 0;}

再怎么风光明媚的自家山川,

zoj 3041 City Selection(数学啊)

相关文章:

你感兴趣的文章:

标签云: