Ultraviolet A 1382-distant galaxy

Source: Internet
Author: User

Question Link

1. The coordinate value is relatively large, so the discretization coordinates

2. The absolute value of coordinates cannot exceed 10 ^ 9, indicating that there may be negative numbers. Therefore, convert all coordinates to positive values (plus 10 ^ 9)

3. Mat [I] [J] indicates (0, 0) (I, j) the number of points within the vertex rectangle including the boundary.

4. enumerate the upper and lower bounds of the rectangle and select the left and right boundary. For the left and right boundary left and right, if R3 is left and L3 is right, the number is:

L1 + l2 + l3-(R1 + R2) + R3.

To maximize the vertices on the rectangle with the right boundary of L3, The r3-(R1 + R2) value should be maximized.

Therefore, enumerate the right boundary J and maintain the maximum value of r3-(R1 + R2) on the left of J, As long as O (n) can determine the answer.

5. Note that all vertices may be in the same straight line. Therefore, add another vertex to both the horizontal and right coordinates.

Code:

# Include <cstdio> # include <cstring> # include <vector> # include <algorithm> # include <iostream> using namespace STD; const int maxn = 110; const int add = 1e9 + 10; int N; int arr [maxn] [2]; int mat [maxn] [maxn]; int X [maxn], Y [maxn], row, Col; inline int findid (int * a, int Len, int X) {return lower_bound (A, A + Len, x)-A + 1 ;} inline void input () {ROW = 1, Col = 1; X [0] = Y [0] = 0; For (INT I = 0; I <N; ++ I) {scanf ("% d", & ar R [I] [0], & arr [I] [1]); X [row ++] = arr [I] [0] + = add; Y [col ++] = arr [I] [1] + = add;} Sort (x, x + row); ROW = unique (x, x + row) -X; sort (Y, Y + col); Col = unique (Y, Y + col)-y; memset (MAT, 0, sizeof (MAT )); for (INT I = 0; I <n; ++ I) {int A = findid (x, row, arr [I] [0]); int B = findid (Y, Col, arr [I] [1]); MAT [a] [B] = 1 ;}for (INT I = 1; I <= row; ++ I) {for (Int J = 1; j <= Col; ++ J) mat [I] [J] + = mat [I] [J-1] + mat [I-1] [J]-mat [I-1] [J-1];} inline int solve () {int ans = 1; // enumerate upper and lower bounds for (INT up = 1; up <row; ++ up) {for (INT down = up + 1; down <= row; ++ down) {int Maxx = mat [Down] [1]-mat [Up-1] [1]; for (INT I = 2; I <= Col; ++ I) {int right = mat [Down] [I]-mat [down-1] [I] + mat [Up] [I]-mat [Up-1] [I] + mat [down-1] [I]-mat [Up] [I]-(MAT [down-1] [I-1]-mat [Up] [I-1]); ans = max (ANS, right + Maxx ); int TMP = mat [Down] [I]-mat [Up-1] [I]-(MAT [Down] [I-1]-m At [Up-1] [I-1]); TMP-= mat [Down] [I]-mat [down-1] [I] + mat [Up] [I]-mat [Up-1] [I]; if (TMP> Maxx) Maxx = TMP ;}} return ans ;}int main () {int CAS = 1; while (~ Scanf ("% d", & N) {input (); printf ("case % d: % d \ n", CAS ++, solve ();} return 0 ;}

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.