poj 1836 Alignment
来源:互联网 发布:淘宝卖家的基本义务 编辑:程序博客网 时间:2024/06/05 02:48
题目大意:
给定一排人的身高,求踢出最少的人可以使队列身高如下形状:
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.
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]
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
81.86 1.86 1.30621 2 1.4 1 1.97 2.2
Sample Output
4
/*
/*
/*#include <iostream>
#include<cstdio>
using namespace std;
int r_dp[1010];
int l_dp[1010];
double num[1010];
int maxn;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>num[i];
l_dp[i]=r_dp[i]=1;
}
maxn=0;
for(int i=1;i<=n;i++)
{
maxn=0;
for(int j=1;j<i;j++)
{
if(num[i]>num[j])
maxn=max(maxn,l_dp[j]);
}
l_dp[i]=maxn+1;
}
for(int i=n;i>=1;i--)
{
maxn=0;
for(int j=n;j>i;j--)
{
if(num[i]>num[j])
maxn=max(maxn,r_dp[j]);
}
r_dp[i]=maxn+1;
}
for(int i=1;i<=n;i++)
l_dp[i]=max(l_dp[i],l_dp[i-1]);
for(int i=n;i>=1;i--)
r_dp[i]=max(r_dp[i+1],r_dp[i]);
maxn=0;
for(int i=1;i<=n;i++)
{
maxn=max(maxn,r_dp[i+1]+l_dp[i]);
}
cout<<n-maxn<<endl;
return 0;
}*/
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
int n,i,j;
double a[1010];
int lenl[1010],lenr[1010];
int maxn;
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
lenl[0]=1;
for(i=1;i<n;i++)
{
maxn=0;
for(j=0;j<i;j++)
{
if(a[i]>a[j]&&maxn<lenl[j])
maxn=lenl[j];
}
lenl[i]=maxn+1;
}
lenr[n-1]=1;
for(i=n-2;i>=0;i--)
{
maxn=0;
for(j=i+1;j<n;j++)
{
if(a[i]>a[j]&&maxn<lenr[j])
maxn=lenr[j];
}
lenr[i]=maxn+1;
}
maxn=0;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(lenl[i]+lenr[j]>maxn)
maxn=lenl[i]+lenr[j];
}
}
cout<<n-maxn<<endl;
}
/*
/*#include <iostream>
#include<cstdio>
using namespace std;
int r_dp[1010];
int l_dp[1010];
double num[1010];
int maxn;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>num[i];
l_dp[i]=r_dp[i]=1;
}
maxn=0;
for(int i=1;i<=n;i++)
{
maxn=0;
for(int j=1;j<i;j++)
{
if(num[i]>num[j])
maxn=max(maxn,l_dp[j]);
}
l_dp[i]=maxn+1;
}
for(int i=n;i>=1;i--)
{
maxn=0;
for(int j=n;j>i;j--)
{
if(num[i]>num[j])
maxn=max(maxn,r_dp[j]);
}
r_dp[i]=maxn+1;
}
for(int i=1;i<=n;i++)
l_dp[i]=max(l_dp[i],l_dp[i-1]);
for(int i=n;i>=1;i--)
r_dp[i]=max(r_dp[i+1],r_dp[i]);
maxn=0;
for(int i=1;i<=n;i++)
{
maxn=max(maxn,r_dp[i+1]+l_dp[i]);
}
cout<<n-maxn<<endl;
return 0;
}*/
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
int n,i,j;
double a[1010];
int lenl[1010],lenr[1010];
int maxn;
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
lenl[0]=1;
for(i=1;i<n;i++)
{
maxn=0;
for(j=0;j<i;j++)
{
if(a[i]>a[j]&&maxn<lenl[j])
maxn=lenl[j];
}
lenl[i]=maxn+1;
}
lenr[n-1]=1;
for(i=n-2;i>=0;i--)
{
maxn=0;
for(j=i+1;j<n;j++)
{
if(a[i]>a[j]&&maxn<lenr[j])
maxn=lenr[j];
}
lenr[i]=maxn+1;
}
maxn=0;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(lenl[i]+lenr[j]>maxn)
maxn=lenl[i]+lenr[j];
}
}
cout<<n-maxn<<endl;
}
0 0
- POJ 1836 Alignment
- POJ 1836 Alignment
- poj 1836 Alignment
- Poj 1836 Alignment
- poj 1836 Alignment
- POJ 1836-Alignment
- poj 1836 Alignment
- POJ 1836 Alignment
- POJ 1836 Alignment
- POJ 1836 Alignment
- POJ 1836 Alignment
- POJ 1836 Alignment
- POJ 1836 Alignment
- poj 1836 Alignment
- poj 1836 Alignment
- poj 1836 Alignment
- POJ - 1836 Alignment
- poj 1836 Alignment
- tarjan学习笔记(poj2186&&bzoj1051受欢迎的牛)
- STM32F10xx复位和时钟控制(RCC)一览
- Android属性动画完全解析(下),Interpolator和ViewPropertyAnimator的用法
- <string>和<string.h>
- CSS 4.3 样式-字体
- poj 1836 Alignment
- Windows 环境下构建 Mesa 12.0.3
- 2013 后苹果 MAC 安装 WINDOWS 教程
- SSH
- AES加密JAVA
- Map与Reduce
- 学习python需要掌握的技能
- Codevs 1058 合唱队形 ---2004年NOIP全国联赛提高组 dp
- Linux下 用的Ncurses做界面 中文乱码解决