Alignment

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
#include"iostream"
#include"algorithm"
using namespace std;
const int ms=1001;
int main()
{
    int n,i,j,k;
    double a[ms];
    int l[ms],r[ms];
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    for(i=1;i<=n;i++)
    {
        l[i]=1;
        for(j=1;j<i;j++)
            if(a[j]<a[i])
                l[i]=max(l[i],l[j]+1);
    }
    for(i=n;i>0;i--)
    {
        r[i]=1;
        for(j=n;j>i;j--)
            if(a[i]>a[j])
                r[i]=max(r[i],r[j]+1);
    }
    int ans=0;
    for(i=1;i<=n;i++)
    {
        int tmp=0;
        for(j=i+1;j<=n;j++)
            if(a[i]>=a[j])
                tmp=max(tmp,r[j]);
        ans=max(ans,tmp+l[i]);
    }
    cout<<n-ans<<endl;
    return 0;
}

Alignment

时间: 2024-09-30 21:57:51

Alignment的相关文章

Data alignment漫谈

特此声明:本人CSDN中的所有文章未经授权,不得转载,违者必究!一切被授权人.组织等的信息都会记录在本人CSDN授权文章的列表中. 以下讨论的概念性的东西应该都是适用于所有系统的,但是实际操作都是linux系统做的. 讨论基于单线程处理,目的是为了简化讨论,简化测试,但并不影响对理论的验证. 最后附上验证源码以及其解释. 背景之个人理解 本节内容都是个人的理解,如果有不正确的地方,欢迎讨论. 说内存对齐之前,先说说硬盘对数据的组织方式.我们知道,文件系统管理数据是按照块来管理的,假如说一个4k对

Supervised Descent Method Face Alignment 代码下载 和 算法研究 之一

1 主要内容: Supervised Descent Method and its Applications to Face Alignment算法研究. 2代码彩蛋:我问了好久,xxiong好心人发给我的,希望能对你们学习有帮助: 低调下载: http://humansensing.cs.cmu.edu/xxiong/mexintraface1.3.1%28release%29.zip. 注意杜绝一切商业用途,如果需要商业用途,请联系作者本人!! 3本文分为几个部分: (1)解决什么问题 (2

SHUOJ A序列 &amp;&amp; POJ 1836 Alignment [动态规划 LIS]

A序列 发布时间: 2017年7月8日 21:16   最后更新: 2017年7月8日 22:29   时间限制: 1000ms   内存限制: 128M 描述 如果一个序列有奇数个正整数组成,不妨令此序列为a1,a2,a3,...,a2?k+1 (0<=k ),并且a1,a2...ak+1 是一个严格递增的序列,ak+1,ak+2,...,a2?k+1 ,是一个严格递减的序列,则称此序列是A序列. 比如1 2 5 4 3就是一个A序列. 现在Jazz有一个长度为n 的数组,他希望让你求出这个数

人脸识别技术大总结1——Face Detection &amp; Alignment

搞了一年人脸识别,寻思着记录点什么,于是想写这么个系列,介绍人脸识别的四大块:Face detection, alignment, verification and identification(recognization),本别代表从一张图中识别出人脸位置,把人脸上的特征点定位,人脸校验和人脸识别.(后两者的区别在于,人脸校验是要给你两张脸问你是不是同一个人,人脸识别是给你一张脸和一个库问你这张脸是库里的谁. 今天先介绍第一部分和第二部分. 主要说三篇顶会文章. ===============

[Sequence Alignment Methods] Dynamic time warping (DTW)

本系列介绍几种序列对齐方法,包括Dynamic time warping (DTW),Smith–Waterman algorithm,Cross-recurrence plot Dynamic time warping (DTW) is a well-known technique to find an optimal alignment between two given (time-dependent) sequences under certain restrictions. ——Mei

存储结构中的对齐(alignment)

最近,在测试基于ceph的小文件合并方案(见上个博文)时,遇到一个怪异的现象:将librados提供的append接口与我们封装的WriteFullObj接口(osd端是append操作和kvdb的put操作)对比,在处理同样大小的文件时(如4KB,8KB等),WriteFullObj比librados的append操作tps低很多,最初怀疑可能是kvdb的put操作的原因,后来将osd端kvdb的put临时去掉,tps仍然上不去:后来使用iostat观察osd上状态,发现WriteFullOb

drawInRect:withFont:lineBreakMode:alignment is deprecated

CGRect myRect = CGRectMake(5,10,200,100) 将 [myText drawInRect:myRect withFont:myFont lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentRight]; 改写成: NSMutableParagraphStyle *textStyle = [[NSMutableParagraphStyle defaultParagraphStyle]muta

POJ1836 Alignment 【LIS(二分)+枚举】

a1,a2,a3,a4,a5,a6...an 对ai求出a1到ai的lis,ai+1到an的lds 取所有ai对应的lis+lds最大值 输出n-lis-lds #include <cstdio> #include <cstdlib> #include <iostream> #include <algorithm> #include <cstring> #include <cmath> using namespace std; int

多重比对multiple alignment

之前只接触过双序列比对,现在需要开始用多序列比对了. 基本概念:多序列比对 - 百科 常用的 multiple alignment 软件: Muscle ClustalW T-coffee 软件之间的比较见文章:Muscle,ClustalW和T-coffee的简单比较

ARMLinux下Alignment trap的一些测试 【转自 李迟的专栏 CSDN http://blog.csdn.net/subfate/article/details/7847356

项目中有时会遇到字节对齐的问题,英文为“Alignment trap”,如果直译,意思为“对齐陷阱”,不过这个说法不太好理解,还是直接用英文来表达. ARM平台下一般是4字节对齐,可以参考文后的给出的文章链接.此处不细说.后面提及“字节对齐” 下面的例子使用了几种重现Alignment trap的方法,例子1是将char*指针直接转换成int*指针,经测试,未发现有字节对齐的问题.例子2和例子3相似,主要是结构体中的字段没有进行对齐(或者访问的地址没有4字节对齐).例子4是直接访问了没有字节对齐