[JOBDU] Topic 1500: Doing drill formation

Source: Internet
Author: User

Title Description:

In high school, every morning the school to organize students and teachers to run to exercise the body, whenever the doing drill to blow, we began to run downstairs, and then the height of the line in front of the team, taller than the queue at the end of the team. Suddenly, one day doing drill in charge of an idea, want to change formation, is when everyone from upstairs ran down, all the students are randomly accounted for in a row, and then doing drill in charge from the team to take out part of the students, so that the remaining students in the team's height from the back, is a first rise after the decline of the "peak" shape. It is said that this shape can bring good luck to everyone, and hope that everyone on the road of learning to climb the peak. (Note that only one side of the mountain can meet the conditions, such as 1, 1, 2, 2, 1 are eligible)

Input:

The input may contain multiple test samples.
For each test case, the first line of input is an integer n (1<=n<=1000000): Represents the number of students that will be entered.
The second line of the input includes n integers: the height of the student (cm) (a positive integer not higher than 200).

Output:

For each test case, output the minimum number of students to be withdrawn.

Sample input:
6100 154 167 159 132 1055152 152 152 152 152
Sample output:
04

The longest increment subsequence problem of the variant, from the left to find again, from the right to look over, and then scan again to find the maximum value of dp1[i] + dp2[i]. The longest increment subsequence can be optimized for the complexity of O (NLOGN) with binary lookups. Handwritten a two-point find Lower_bound function, also can be used in STL.

1#include <iostream>2#include <cstdio>3#include <vector>4#include <algorithm>5 using namespacestd;6  7 intN;8vector<int>v;9vector<int>DP1, DP2;Tenvector<int>St; One   A voidBinsearch (inttarget) { -     if(St.empty () | |-Target >St.back ()) { - St.push_back (target); the}Else { -         intL =0, R = (int) St.size ()-1, M; -          while(L <=r) { -m = L + ((r-l) >>1); +             if(St[m] >= target) r = M-1; -             ElseL = m +1; +         } AST[L] =Target; at     } - } -   - voidGETDP () { - st.clear (); -      for(inti =0; I < v.size (); ++i) { in Binsearch (V[i]); -Dp1[i] =st.size (); to     } + st.clear (); -      for(inti = (int) V.size ()-1; I >=0; --i) { the Binsearch (V[i]); *Dp2[i] =st.size (); $     }Panax Notoginseng } -   the voidsolve () { + GETDP (); A     intres =0; the      for(inti =0; i < N; ++i) { +res = max (res, dp1[i] + dp2[i]-1); -     } $cout << n-res <<Endl; $ } -   - intMain () { the      while(SCANF ("%d", &n)! =EOF) { - v.resize (N);Wuyi dp1.resize (N); the dp2.resize (N); -          for(inti =0; i < N; ++i) scanf ("%d", &v[i]); Wu solve (); -     } About     return 0; $ } - /************************************************************** - problem:1500 - user:hupo250 A language:c++ + result:accepted the time:1050 Ms - memory:13244 KB $ ****************************************************************/

[JOBDU] Topic 1500: Doing drill formation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.