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