La 3695 distant galaxy

Source: Internet
Author: User
Tags define local

The coordinates of N points are given (the coordinates are all positive numbers), and the maximum number of points can be on the boundary of a rectangle.

In the solution, several arrays are constructed, which are displayed in the figure.

First, two horizontal lines are enumerated. Then left [I] indicates the point on the left of the vertical line I, and on [I] indicates the two horizontal lines on the vertical line I (not on the horizontal line) the number of points. on2 [I] indicates the number of points that are located between the two horizontal lines on the vertical line I plus the horizontal line boundary.

So the points on the rectangle frame are:

Left [J]-left [I] + on [I] + on2 [J]

Enumerate the right boundary vertical line J. After J is determined, maintain the maximum value of on [I]-left [I.

 

1 // # define local 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 using namespace STD; 6 7 const int maxn = 100 + 10; 8 int n, m, Y [maxn], on [maxn], on2 [maxn], left [maxn]; 9 10 struct point11 {12 int x, Y; 13 bool operator <(const point & RHs) const14 {15 return x <RHS. x; 16} 17} p [maxn]; 18 19 int solve () 20 {21 sort (p, p + n); 22 sort (Y, Y + n ); 23 m = unique (Y, Y + n)-y; // m is different from Y coordinate 24 if (M <= 2) 25 return N; 26 27 int ans = 0; 28 for (int A = 0; A <m; ++) 29 for (int B = a + 1; B <m; ++ B) 30 {31 int ymin = Y [a], Ymax = Y [B]; 32 33 // calculate left, on, on234 int K = 0; // K record the number of bars 35 for (INT I = 0; I <n; ++ I) 36 {37 if (I = 0 | P [I]. x! = P [I-1]. x) 38 {// This is a new vertical line 39 + + k; 40 on [k] = on2 [k] = 0; 41 left [k] = k = 0? 0: left [k-1] + on2 [k-1]-on [k-1]; 42} 43 If (P [I]. y> ymin & P [I]. Y <Ymax) 44 + + on [k]; 45 if (P [I]. y> = ymin & P [I]. Y <= Ymax) 46 + + on2 [k]; 47} 48 if (k <= 2) 49 return N; 50 51 int m = 0; 52 for (Int J = 1; j <= K; ++ J) 53 {54 ans = max (ANS, left [J] + on2 [J] + M ); 55 m = max (M, on [J]-left [J]); 56} 57} 58 59 return ans; 60} 61 62 int main (void) 63 {64 # ifdef local65 freopen ("rj5in.txt", "r", stdin); 66 # endif67 68 int Kase = 0; 69 while (scanf ("% d ", & n) = 1 & N) 70 {71 for (INT I = 0; I <n; ++ I) 72 {73 scanf ("% d ", & P [I]. x, & P [I]. y); 74 y [I] = P [I]. y; 75} 76 printf ("case % d: % d \ n", ++ Kase, solve (); 77} 78 return 0; 79}
Code Jun

 

Conclusion: The question in the big white book is wonderful, and you cannot fully understand the essence of the question after careful consideration. It must be because I am too weak to answer questions.

 

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.