Hdoj/hdu 2555 Everyone can participate in the 30th Annual school Athletics Games (judging plus sort ~)

Source: Internet
Author: User
Tags abs

Problem Description
The 29th session of Hangzhou Normal University track and field games successfully closed, this games is the largest in our school, the biggest number of participants in a sports meeting. In two days and a half, 61 teams of students and faculty members participated in the competition with a total of 2,664 athletes. During the competition, athletes competed out of style, race out of the level, a total of 9 people broke 6 school records.
Our dormitory 4 students are my class the most hardworking cheerleaders, every day in the stands for the class of athletes cheering, for my class won the Spiritual Civilization Award made a contribution. Unfortunately, as with nearly 20,000 other students in our school, we cannot play on our own: (
So, our 4 students for the next school sports will have invented a game that everyone can participate in:
On the ground there are n different sizes of rectangular traps, each trap has a different perimeter, each contestant has a bag, close their eyes to throw it to the ground, if the bag fell into a trap, then the contestant according to the length of the perimeter of the trap (such as 50 meters), around the runway run trap perimeter length (such as 50 meters), If the sandbags do not fall into any trap, then congratulations, you run 0 meters.
M<20000 a classmate to participate in the competition, in order to run the most three students (champion, runner-up, runner-up) to award consolation prize, must give the M-classmate's running length according to from more to less sort.
As in the same coordinate system and rectangle, the four edges of these rectangles (traps) are parallel to the x-axis or y-axis, and they intersect each other, and their top-left vertex coordinates are known as the coordinates of the vertex at the lower-right corner, given the coordinates of the sandbags you throw (as a point), you can get the distance you want to (Note that the coordinate values here are not more than 10000)

Input
The first line is the two positive integer m<20000,n<100, which indicates that M-students took part in the throwing sandbags game and had n traps.
Then the M-line is the coordinates of the sandbags thrown by M-students, each of which is a two positive integer.
The next n rows are the coordinates of the trap, with 4 positive integers in each row, from left to right: the value of the horizontal axis of the vertex at the bottom left corner of the trap, the ordinate value of the vertex in the lower left corner of the trap, the horizontal axis of the top right corner of the trap, and the ordinate value of the top right corner vertex

Output
M students by how much distance to run, from more to less output, a number line.

Sample Input
5 3
15 27
32 93
22 3
98 4
65 23
22 65 100 76
2 5 7 9
54 6 94 24

Sample Output
116
0
0
0
0

The main topic: give you m a classmate lost the location of the sandbags, and n the diagonal coordinates of the rectangle, for each classmate, if the bag in a rectangle, then the classmate running distance for the circumference of the rectangle, if not in any one rectangle, then the students running distance of 0 meters, all students running distance from large to small sort and output.

Analysis: Just compare, traverse each trap, and determine if that point is in that trap (including the boundary!!!). If it is, it is equal to the perimeter of the trap ~

This topic is the place where the father is ~ there may be 2 or more traps of the edge will overlap ~ and the topic said do not intersect ~ We just found that point in the first in which traps on the ~break jump out of the loop, no need to look down ~
I'll comment in the code ~

Import Java.util.arrays;import Java.util.Scanner; Public classmain{ Public Static void Main(string[] args) {Scanner SC =NewScanner (System.inch); while(Sc.hasnext ()) {intM =sc.nextint ();intn =sc.nextint ();intA[][] =New int[M] [2];intB[][] =New intN [4]; for(intI=0; i<m;i++) {a[i][0] = Sc.nextint (); a[i][1] = Sc.nextint (); } for(intI=0; i<n;i++) {b[i][0] =sc.nextint (); b[i][1] =sc.nextint (); b[i][2] =sc.nextint (); b[i][3] =sc.nextint (); }intNum[] =New int[M]; for(intI=0; i<m;i++) {num[i]=0; for(intj=0; j<n;j++) {if(a[i][0]>=b[j][0]&&a[i][0]<=b[j][2]&&a[i][1]>=b[j][1]&&a[i][1]<=b[j][3]) {num[i]=2*math.abs ((b[j][2]-b[j][0]) )+2*math.abs ((b[j][3]-b[j][1]) ); Break;//If you don't have this break, WA                            //Test instructions problem! Because if you follow what it says,//traps do not intersect, there is no such break is actually the same! But the truth is, without this break, WA}}} arrays.sort (num); for(inti=num.length-1; i>=0; i--) {System. out. println (Num[i]); }        }    }}

Hdoj/hdu 2555 Everyone can participate in the 30th Annual school Athletics Games (judging plus sort ~)

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.