This problem from the beginning to see it to make, has been over the fast two weeks "because the first thought completely ran biased to write is the violent simulation want to water too";
The test instructions is this:
in addition to the domino interest, JZABC is also interested in racing cars. He watched a racing game last weekend. He can always come up with many strange problems. At one point, he saw N cars (always traveling at a constant speed) in the same straight line, and on an infinite length of straights, and N cars have a strict succession of points. He measured the speed of each car through special equipment. Then the problem arises, if there are two cars A and B cars, a car behind the B car, and a car faster than the B car, then after a period of time, a car will be more than B car. We call it a overtaking. Then he would ask you to help calculate the total number of overtaking. We remember that the coordinates of the beginning of the driveway are 0. No two cars have the same coordinates.
Input:
The first line, a number n, the total number of vehicles.
Second line to line n+1, information for n vehicles
There is a space between two positive integers x,y,x and y per line
X is the coordinates of the car, y is the speed of the car
0<x,y<=1000000000
Output: Total number of overtaking "in reverse order"
First of all, the first time I didn't read. Test instructions: Open a structure, according to the coordinates from small to large sort record the order, then sort by speed, with the total minus each position, and then accumulate. Later found that if the speed of large in the previous large number can not be exceeded, and record it before the total number of cars-1 whether from time or strategy are difficult to meet "has been ranked by speed is not possible from 1 cycle to this car."
Then from the book to see the problem, was prepared to see the code to try, and then Yyx classmate told me this code is a bug, I believe, do not dare to play, in fact, the code on the certificate is correct Orz
It turns out that it's good to try to think of something. The idea of solving a problem is to separate and sort the sequence, then merge the two rows. Because the sequence of the two sides is orderly, then the number selected on the side and the other side, the previous number must be full
are in reverse order. Sorting and counting are done at the same time without affecting the final answer. PS: Pay attention to the amount of statistical data ... Will explode int.
P1136 merge Sort, find the number of reverse order