UVA-1382 Distant Galaxy

Source: Internet
Author: User

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, &AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.