HDU 4007 Dave

Source: Internet
Author: User

Typical statistical questions

Question:

Returns the coordinates of N people and obtains the maximum number of people in the square with the edge of R.

Analysis:

Because the position of the square is not fixed and the most covered point must be satisfied, the Y coordinate of a certain point must be used as the bottom boundary to have the optimal solution. ALL:

First, sort the ordinate values of N people, enumerate all Y coordinates (the bottom boundary of a square), and find the points within the Square that satisfy the current y coordinate, enumerate the X coordinates of the points that meet the conditions, and calculate the points that can be overwritten with the R side. The total complexity is O (n ^ 2)

Code:

# Include <iostream> # include <algorithm> using namespace STD; struct node {int X, Y;} p [1001]; int N, ANS, R, XX [1001], YY [1001]; int main () {While (scanf ("% d", & N, & R) = 2) {for (INT I = 1; I <= N; I ++) {scanf ("% d", & P [I]. x, & P [I]. y); YY [I] = P [I]. y;} Sort (yy + 1, YY + 1 + n); ans = 0; For (Int J = 1; j <= N; j ++) // enumerate the bottom boundary {int CNT = 0; For (INT I = 1; I <= N; I ++) if (P [I]. y> = YY [J] & P [I]. Y <= YY [J] + r) xx [CNT ++] = P [I]. x; // locate all the points that meet the current bottom boundary, sort (XX, xx + CNT); XX [CNT] = int_max; // used to exit the while loop int e = 0; for (INT I = 0; I <CNT; I ++) // obtain the edge with the Left Border of the current point and the side length is R, points that can be overwritten at most {While (XX [e] <= XX [I] + r) e ++; ans = max (ANS, e-I );}} printf ("% d \ n", ANS);} return 0 ;}
Related Keywords:

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.