Title Link: ZOJ 3041 city Selection
Test instructions: There are n city coordinates and m factory coordinates, which are contaminated at points in the fourth quadrant at the factory origin. Draw line area in figure
Idea: Sort the coordinates of the factory and the city, and then compare the y-coordinate.
AC Code:
#include <stdio.h> #include <algorithm> #include <set>using namespace std;const int maxn=200010; struct node{int x,y;int flag;}; struct node P[maxn*2],tmp,ans[maxn];bool cmp1 (node A,node b) {if (a.x!=b.x) return a.x<b.x;if (A.Y!=B.Y) return a.y> B.y;return A.flag<b.flag;} BOOL CMP2 (node A,node b) {if (a.x!=b.x) return a.x<b.x;if (A.Y!=B.Y) return a.y<b.y;} int main () {int n,m,i,j,count;while (scanf ("%d%d", &n,&m)!=eof) {int cnt=0;for (i=0;i<n;i++) {scanf ("%d%d", &TMP.X,&TMP.Y); tmp.flag=1;p[cnt++]=tmp;} for (i=0;i<m;i++) {scanf ("%d%d", &tmp.x,&tmp.y); tmp.flag=0;p[cnt++]=tmp;} Sort (P,P+CNT,CMP1); Tmp.x=-1000000010;tmp.y=-1000000010;count=0;for (i=0;i<cnt;i++) {if (p[i].flag==0 && P[I].Y>=TMP.Y) tmp.y=p[i].y;if (p[i].flag==1 && p[i].y>tmp.y) ans[count++]=p[i];} Sort (ANS,ANS+COUNT,CMP2);p rintf ("%d\n", Count), for (i=0;i<count;i++) {printf ("%d%d\n", ANS[I].X,ANS[I].Y);}} return 0;} /*7 3-3 30 1-2 21 34 23 45 5-2 22 04 45 30 1-2 21 41 34 4-2 22 04 31 10 0-1 0*/
ZOJ 3041 City Selection (Good sort)