Description
Solution
The game found a pattern, but no proof ... (Of course, finally AC ...) )
It is clear that the number of operations that are not being manipulated must be sequential in the sequence.
Therefore, the number of operations that are not manipulated must increment continuously from left to right (for example, 23456).
And the number of questions required to be manipulated as little as possible, is not the number of operations as many, to find the longest paragraph to meet the conditions can be.
For example, for data 1 4 5 3 2 6 7 9 8, the longest segment is 45678, so the minimum number of operations is 4.
Attached method:
3 Pre-=>314526798
2 Pre-=>231456798
1 Pre-=>123456798
9 Post-=>123456789
To get to the top, find out the longest length of Len, then N-len is the answer.
similar to dynamic planning, for the number of a, if A!=1 and the previous A-1 (can be maintained with the array), then f[i]=f[appears A-1 location]+1, otherwise f[i]=1. The answer is N-f[n]. The complexity of O (n).
Expand:
① if the title asks for a way out? (SPJ, of course)
② if it is not the 1~n arrangement but can have the repetition number?
Code
404 Not Found
View Code
2017-10-5 simulation T2 Small Z Love sort (sorting.*)