Alignment
Alignment
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 14547 Accepted: 4718
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
Romania OI 2002
大神的博客讲的很详细
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int,int>p;
const int INF = 0x3f3f3f3f;
int DpL[1100];
int DpR[1100];
double a[1100];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=1; i<=n; i++)
{
scanf("%lf",&a[i]);
}
for(int i=1; i<=n; i++)
{
DpL[i]=1;
int sum=0;
int j=i-1;
while(j>=1)
{
if(a[i]>a[j])
sum=max(sum,DpL[j]);
j--;
}
DpL[i]+=sum;
}
for(int i=n;i>=1;i--)
{
int sum=0;
int j=i+1;
DpR[i]=1;
while(j<=n)
{
if(a[i]>a[j])
{
sum=max(sum,DpR[j]);
}
j++;
}
DpR[i]+=sum;
}
int sum=0;
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
sum=max(sum,DpL[i]+DpR[j]);
}
}
printf("%d\n",n-sum);
}
return 0;
}
Alignment的更多相关文章
- Alignment trap 解决方法 【转 结合上一篇
前几天交叉编译crtmpserver到arm9下.编译通过,但是运行的时候,总是提示Alignment trap,但是并不影响程序的运行.这依然很令人不爽,因为不知道是什么原因引起的,这就像一颗定时炸 ...
- ARMLinux下Alignment trap的一些测试 【转自 李迟的专栏 CSDN http://blog.csdn.net/subfate/article/details/7847356
项目中有时会遇到字节对齐的问题,英文为“Alignment trap”,如果直译,意思为“对齐陷阱”,不过这个说法不太好理解,还是直接用英文来表达. ARM平台下一般是4字节对齐,可以参考文后的给出的 ...
- Multiple sequence alignment Benchmark Data set
Multiple sequence alignment Benchmark Data set 1. 汇总: 序列比对标准数据集: http://www.drive5.com/bench/ This i ...
- POJ 1836 Alignment
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11450 Accepted: 3647 Descriptio ...
- cf.295.C.DNA Alignment(数学推导)
DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 多重比对multiple alignment
之前只接触过双序列比对,现在需要开始用多序列比对了. 基本概念:多序列比对 - 百科 常用的 multiple alignment 软件: Muscle ClustalW T-coffee 软件之间的 ...
- Sublime text 2下alignment插件无效的解决办法
在sublime text 2中安装了alignment插件,但使用快捷键‘ctrl+alt+a'无效,经过各种方法依然无效,最后找到了这个“Doesn't work at all for me (f ...
- 存储结构中的对齐(alignment)
最近,在测试基于ceph的小文件合并方案(见上个博文)时,遇到一个怪异的现象:将librados提供的append接口与我们封装的WriteFullObj接口(osd端是append操作和kvdb的p ...
- 编写跨平台代码之memory alignment
编写网络包(存储在堆上)转换程序时,在hp-ux机器上运行时会遇到 si_code: 1 - BUS_ADRALN - Invalid address alignment. Please refer ...
随机推荐
- Java基础之一组有用的类——使用Scanner对象(TryScanner)
控制台程序. java.util.Scanner类定义的对象使用正则表达式来扫描来自各种源的字符输入,并把输入显示为各种基本类型的一系列标记或者显示为字符串. 默认情况下,Scanner对象读取标记时 ...
- IDEA中 @override报错的处理步骤
今天用IDEA导入一个java工程时,JDK1.8版本,碰上一个问题,代码中所有@override处标红,并提示:@override不支持对接口的实现. 网上百度了一下发现, 原因是引用JDK5版本中 ...
- Leetcode: Convert a Number to Hexadecimal
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two's compl ...
- HDU 5000 Clone(离散数学+DP)(2014 ACM/ICPC Asia Regional Anshan Online)
Problem Description After eating food from Chernobyl, DRD got a super power: he could clone himself ...
- kafka管理器kafka-manager部署安装
运行的环境要求 Kafka 0.8.1.1+ sbt 0.13.x Java 7+ 功能 为了简化开发者和服务工程师维护Kafka集群的工作,yahoo构建了一个叫做Kafka管理器的基于Web工具, ...
- ansible自动化运维工具的安装与使用
运行环境 centOS6.6 ansible ansible的功能还是比较多的,博主只用它在集群上进行批量部署软件和维护的功能,其他不多做研究,有需要的话这篇文章会慢慢补充. ansible特点 轻量 ...
- 使用console进行 性能测试 和 计算代码运行时间(转载)
本文转载自: 使用console进行 性能测试 和 计算代码运行时间
- JavaScript获取后台C#变量以及调用后台方法
http://www.educity.cn/develop/495493.html 有时需要在JavaScript中获取后台变量的值,来判断JavaScript的执行逻辑,或者需要调用C#后台方法获取 ...
- 膜拜acm大牛 虽然我不会这题,但是AC还是没有问题的~(转自hzwer)
wywcgs: 亦称Lord Wu,俗名吴垠,2009级厦门大学智能科学与技术学院研究生,本科就读于哈尔滨工业大学.因其深厚的算法功底与独到的思维方式,被尊为“吴教主”,至今声威犹存. 2006年起参 ...
- origin 8.5 曲线拟合,延长曲线范围
1. 输入数据并选择Y轴数据 2 非线性拟合 Analysis—Fitting—Nonlinear Curve Fit—Open Dialog 3.选择拟合曲线类型 在origin7.5中选择曲线类型 ...