Deque explanations ideas

//
the Description

Sherry now face a difficult problem, there is need to sort N integers.
Sherry hand tool that can be used several deque.

She needs in order to deal with this number N, for each number, Sherry can do two things:
1. Create a deque, and the current number as a unique number in the queue;
2. Before the current head number into existing or after the end of the queue.

After completion of all processed, Sherry these queues ordered sequence can be obtained after a nondecreasing.
Input
The first row contains an integer N, the number of integers. The following N lines contains an integer Di, where Di represents an integer of processing required.
Output
contains a single row, for the deque Sherry minimum number required.
N <= 200000

//


 

Problem-solving ideas
1. First n the range n <= 200,000, it is clear that we need a time complexity of the algorithm in nlogn below. Then it is clear that the thought of the sort.
2. known meaning of the questions, the number of columns actually obtained after sorting a plurality deque composition
That is, a subject becomes in an ordered sequence to find the minimum number of deque.
3. push obviously know, every element subscript a double-ended queue is clearly in line with a first and then a monotonically increasing monotonically decreasing characteristic.
That is
the subject becomes a sequence of looking inside a length n inflection (inflection)

Then the total problem-solving ideas settle down
first order. And because the subscript after the required operation related to, we need to define a data structure to store rather than an array.
Then repeated for the number of records combined and
the final core code - to calculate the number of flags and similar inflection retain the current number
(difficulty becomes popular)
Code ugly hold the (√)

Guess you like

Origin www.cnblogs.com/Malthael/p/11240331.html