The main topic: Give n points, ask a parallel with the x-axis and the y-axis of the rectangle, the maximum number of points can be left on the edge.
Problem-solving ideas: first put the y-axis together, then enumerate the left and right boundary, consider the upper and lower boundary, maintain the maximum value
#include <cstdio>#include <algorithm>using namespace STD;structPoint {intXintYBOOL operator< (Constpoint& a)Const{returnx < a.x; }};Const intMAXN = -+Ten; Point P[MAXN];intY[MAXN], ON[MAXN], ON2[MAXN], LEFT[MAXN];intSolveintN) {sort (p, p + N); Sort (y, y + N);intm = Unique (y, y + N)-y;if(M <=2)returnNintAns =0; for(intA =0; A < M; a++) for(intb = A +1; b < m; b++) {intYmin = Y[a], ymax = y[b];intK =0; for(inti =0; i < N; i++) {if(i = =0|| P[i].x! = p[i-1].x) {k++; ON[K] = on2[k] =0; Left[k] = left[k-1] + on2[k-1]-on[k-1]; }if(P[i].y > Ymin && p[i].y < ymax) on[k]++;if(p[i].y >= ymin && p[i].y <= ymax) on2[k]++; }if(k <=2)returnNintM =0; for(intj =1; J <= K; J + +) {ans = max (ans, left[j] + on2[j] + M); m = max (M, On[j]-left[j]); } }returnAns;}intMain () {intN, Kase =0; while(scanf("%d", &n), N) { for(inti =0; i < N; i++) {scanf("%d%d", &p[i].x, &P[I].Y); Y[i] = p[i].y; }printf("Case%d:%d\n", ++kase, Solve (N)); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVA-1382 Distant Galaxy