Online Evaluation:
http://codevs.cn/problem/3286/
Overall idea:
First we look at the question, under what circumstances the sum is the smallest, we rely on the man's intuition found that if the two sequence is ordered, then this is the smallest, this is easy to prove by a few unknowns, well, we found how to minimize the distance. But how do we ask for the minimum number of interchange steps, we can find the position of each number in a sequence, and the number of pairs in the B sequence, by several sorts. We then ask that this sequence (CI is the number of pairs of AI paired with the subscript in B) is the result of the reverse. As for why is the reverse order, we can use a pen to simulate, we found in the pairing of the sequence of the subscript, we just have to exchange all the adjacent reverse order can be, and the original non-reverse but not satisfied with the conditions will be in the process of exchanging reverse order to meet. So the reverse order is the demand.
So how do you ask for reverse order?
We can find in the process of merging sorting,
Suppose that an original sequence is ordered at a time of two sequences, when they are ordered and assembled.
We find that if a number of <a sequences in the B sequence are not assembled in the first number, then he must be the number of all the remaining a series not assembled, then the number of reverse pairs can be added to these, as to correctness, because the merge sort a, a two sequence in the Assembly has not happened before the relationship, So the number of sequence elements in B is a sequence number in a certain >a.
Where the error is:
began to write only a n^2 of violence solution, did not see is reverse, only 80 points, later changed to reverse order, and then in the writing merge sort of time less sentenced a condition,
| 1 |
if ((T[you] >= T[zuo] && zuo <= midn) | | (You > Y)) |
Less write Zuo <= midn then my merge sort on the Ghost livestock,,, the common algorithm really should write well, not as usual, a sort of thing,,,,
And then forget to take the mold,,, again 80,qaq
Experience:
Whether difficult or not, put flat mentality, always get a lot of points, the same problem should be more to think about, see if there is no model behind, and the usual algorithm should be more practice, do not rely too much on C + + STD,
AC Code:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |