POJ 1828 Problem Solving report

Source: Internet
Author: User

Problem Translation


Given the coordinates (X, Y) of each monkey in the monkey mountains, find out the number of monkeys that meet the conditions that no other monkey has at the same time greater than or equal to the X axis and Y axis coordinates.


Solution


Let's take a look at the situation where the coordinate (X, Y) of a vertex is greater than that of another vertex (X0, Y0) in the coordinate axis, such:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/21143225H-0.png "title =" .png "style =" font-family: 'lucida grande ', 'trebuchet ms', verdana, helvetica, sans-serif; margin: 5px 10px; padding: 6px; height: auto; max-width: 100%; vertical-align: middle; border-width: 0px 1px 0px; border-style: none solid none; border-color: # b5b5b5; opacity: 1; "/>

We can see that when X> X0 and Y> Y0, we can see that (X0, Y0) is within the projection range of the rectangle enclosed by the vertex (X, Y) and coordinate axis.

Below are extended to general situations:

As shown in, all the points that may become Monkey Kings form a "ladder" in the periphery. If you scan from right to left, use a variable to save the "height" of the current ladder ", if the height of the current vertex is smaller than the step height, the vertex must be in the shadow of another vertex. If the height of the current vertex is greater than the step height, then, the height of the counter is incremented and updated to the height of the new vertex. Note that the x or y coordinates are equal. The complexity of sorting points is O (nlogn), Scanning once is O (n), and the last time complexity is O (nlogn ).

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/2114326459-1.png "title =" image 2.png "style =" margin: 5px 10px; padding: 6px; height: auto; max-width: 100%; vertical-align: middle; border-width: 0px 1px 1px 0px; border-style: none solid none; border-color: # b5b5b5; opacity: 1; "/>



More source code, click http://www.51ojr.com/report/full/36

Related Article

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.