2014
07-10

# 九度1500-出操队形[微策略面试题]

6
100 154 167 159 132 105
5
152 152 152 152 152

0
4

//============================================================================
// Name        : 出操队形.cpp
// Author      : Coder
// Version     :
// Description : http://ac.jobdu.com/problem.php?pid=1500
//============================================================================

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

//在arr中找到的大于等于key的第一个数。没有的话，返回n
//此处也可以直接调用STL里面的lower_bound函数
int lower_bound(int arr[],int n ,int key){
if(n == 0) return 0;
int low = 0;
int high = n-1;
while(low <= high){
int mid = (low+high)/2;
if( arr[mid] < key)
low = mid+1;
else
high = mid-1;
}
return low;
}

//结果存放在res中，res[i]表示 arr[0...i]的最大上升序列的长度。
int lis(int arr[], int n, int res[]){
res[0] = 1;
int lisSize = 1;
int low;
for(int i=1; i<n; i++){
//或调用系统 的lower_bound
/*int * p = lower_bound(arr, arr+lisSize, arr[i]);
low = p - arr;*/
low = lower_bound(arr, lisSize, arr[i]);
//如果超出，更新最大长度
if(low >= lisSize) lisSize = low+1;
//用arr[i]更新较大的那个值
arr[low] = arr[i];
res[i] = lisSize;
}
return lisSize;
}

int main() {
//freopen("in.txt", "r", stdin);
int n;
int * arr, *reverseArr, *res, *reverRes;
while(scanf("%d",&n) != EOF){
arr = new int[n+1];
reverseArr = new int[n+1];
res = new int[n+1];
for(int i=0; i<n; i++) scanf("%d", &arr[i]);
//反向的再计算一次
for(int i=0; i<n; i++) reverseArr[i] = arr[n-i-1];
lis(arr, n, res);
free(arr);
reverRes = new int[n+1];
lis(reverseArr, n, reverRes);
free(reverseArr);
int ans = 0;
for (int i = 0; i < n; i++) {
if (ans < res[i] + reverRes[n - i - 1] - 1)
ans = res[i] + reverRes[n - i - 1] - 1;
}
printf("%d\n", n-ans);
}
return 0;
}

1. ǖǖǖǖǖǖǖǖ操丝袜脚ǖǖǖǖǖǖǖǖǖǖǖǖǖǖǖǖ高跟皮靴ǖǖǖǖǖǖǖǖǖǖǖǖǖǖǖǖ二手丝袜ǖǖǖǖǖǖǖǖǖǖǖǖǖǖǖǖ北京丝袜会所ǖǖǖǖǖǖǖǖǖǖǖǖǖǖǖǖ丝袜mmǖǖǖǖǖǖǖǖǖǖǖǖǖǖǖǖ蓝色丝袜ǖǖǖǖǖǖǖǖǖǖǖǖǖǖǖǖ丝袜花牡丹ǖǖǖǖǖǖǖǖwww.518mei.com

2. ṓṓṓṓṓṓṓṓṓ9oal玉足网ṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓ天鹅绒丝袜ṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓ丝袜艺术ṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓ美腿女侠ṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓ隔着丝袜操ṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓ董卿丝袜ṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓṓ男人穿丝袜ṓṓṓṓṓṓṓṓṓx.meinv95.com