Alignment
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 17331   Accepted: 5694

Description

In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in a straight line in front of the captain. The captain is not satisfied with the way his soldiers are aligned; it is true that the soldiers are aligned in order by their code number: 1 , 2 , 3 , . . . , n , but they are not aligned by their height. The captain asks some soldiers to get out of the line, as the soldiers that remain in the line, without changing their places, but getting closer, to form a new line, where each soldier can see by looking lengthwise the line at least one of the line's extremity (left or right). A soldier see an extremity if there isn't any soldiers with a higher or equal height than his height between him and that extremity.

Write a program that, knowing the height of each soldier, determines
the minimum number of soldiers which have to get out of line.

Input

On the
first line of the input is written the number of the soldiers n. On the
second line is written a series of n floating numbers with at most 5
digits precision and separated by a space character. The k-th number
from this line represents the height of the soldier who has the code k
(1 <= k <= n).

There are some restrictions:

• 2 <= n <= 1000

• the height are floating numbers from the interval [0.5, 2.5]

Output

The only line of output will contain the number of the soldiers who have to get out of the line.

Sample Input

8
1.86 1.86 1.30621 2 1.4 1 1.97 2.2

Sample Output

4

Source

 
  就是一道求LIS的变形题目,注意到浮点数并不大,可以乘以1e5之后转化为整数来操作。
  由于和以前做过的一道题类似,不同的是最高的人不一定只出现一次。题目要求的时只要左边或者右边没有比他高的人就好了,并不是绝对的高低限制。可以枚举每个人作为最高的计算N次,假设i是最高的一个单位,我们计算以i为最后一个点之前的最长子序列,在计算i后面去掉大于ai的最长下降子序列加在一起就是队里的人数。
    对于每次枚举出的最高的人,这个身高可以出现两次,一个左一个右就好了。
 
 #include <iostream>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long LL;
const int MAX = ;
int a[MAX], b[MAX], g[MAX];
int solve(int m,int n)
{
memset(g, inf, sizeof(g));
int i, j, k1=, k2=;
for (i = ;i < m;++i)
{
int k = lower_bound(g,g+n+,a[i])-g;
g[k] = a[i];
}k1 = lower_bound(g, g + n+, a[m]) - g+;
memset(g, inf, sizeof(g));
for (i = ;i <=n-m;++i)
{
if (b[i] > a[m]) continue;
int k = lower_bound(g, g + n+, b[i]) - g;
g[k] = b[i];
k2 = max(k2,k+);
}
//printf("%d %d\n", k1, k2);
return n - (k1 + k2);
}
int main()
{
int N, i, j, k ;
double d;
while (cin >> N) {
int ans = inf;
for (i = ;i <= N;++i)scanf("%lf", &d), a[i] = b[N + - i] = d * ;
for (i = ;i <= N;++i) {
ans = min(ans, solve(i, N));
}
printf("%d\n", ans);
}
return ;
}
 
 
 
 
 
 

最新文章

  1. sql 2008 修改链接服务器 Rpc &amp;Rpc Out
  2. chrome 优秀的插件推荐
  3. cocos2d-x使用python创建vs模板
  4. 合并大量txt文件的内容
  5. H.264中NALU、RBSP、SODB的关系 (弄清码流结构)
  6. 【九度OJ】题目1078-二叉树遍历
  7. ssh远程登录Ubuntu报错:Permission denied, please try again.
  8. ci 笔记
  9. Win7窗口操作
  10. Oracle10g--plSql命令
  11. vdsm的SSL证书验证过程
  12. Java文件下载:如何编码文件名称以及如何设置HttpServletResponse
  13. linux 常用压缩解压命令
  14. O365 Manager Plus帮助台委派功能一览表
  15. redis互斥锁简易设计原理【原】
  16. hihocoder 前两题思路
  17. Codeforces 1077 F2 - Pictures with Kittens (hard version)
  18. Centos7使用PXE+Kickstart无人值守安装服务
  19. 将Word,PDF文档转化为图片
  20. optimizer_switch引起的诡异问题

热门文章

  1. python模块学习(二)
  2. 1、hive安装详细步骤
  3. nodejs get请求
  4. spring boot 2.0添加对fastjson的支持
  5. 跟踪 twisted 里deferred 的Callback
  6. 函数的调用规则(__cdecl,__stdcall,__fastcall,__pascal)
  7. mysql中int(3)与int(11)有什么区别吗?
  8. Linux基本命令 压缩命令
  9. Windos Server 2008 NFS 服务安装使用
  10. Listening Carefully SP1403S