P1966 NOIP2013T2 matches queuing seeking to reverse

The meaning of problems: Title given two equal length sequences, two sequences find the minimum number of exchanges of the two sequences satisfy a value between the sum (ai-bi) ^ 2 minimum;

Solution: merge sort / Fenwick tree + seeking to reverse

1. merge sort / Fenwick tree: Both ways are possible to quickly determine the number of reverse

2. seeking to reverse: because only when the two sequences opposite values ​​are in the same category according to their number in the sequence, to minimize the equation. While the same number corresponds to the movement of the two sequences does not move, so that the title can be converted into a sequence of transformation into a minimum number of moving another sequence. At this time, the minimum number of movements is easy to see a sequence into the sequence b is a number in reverse order;

Guess you like

Origin www.cnblogs.com/nnezgy/p/11366297.html