poj 1836 Alignment
2016-06-10 21:42
375 查看
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
Sample Output
Source
Romania OI 2002
这道题意思是让最少的人出列,使得队伍中的每个人都至少能看见一边的底线(就是说能看见最左边或最右边)
用两次LIS,然后枚举分界点就可以了。
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 15646 | Accepted: 5091 |
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
这道题意思是让最少的人出列,使得队伍中的每个人都至少能看见一边的底线(就是说能看见最左边或最右边)
用两次LIS,然后枚举分界点就可以了。
#include<iostream> #include<cstring> #include<string> #include<cstdio> #include<algorithm> using namespace std; double height[1001]; int dp[1001]; int dp2[1001]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;++i) { scanf("%lf",&height[i]); } for(int i=1;i<=n;++i) { dp[i]=1; for(int j=i-1;j>=1;--j) { if(height[i]>height[j]) { dp[i]=max(dp[i],dp[j]+1); } } } for(int i=n;i>=1;--i) { dp2[i]=1; for(int j=i+1;j<=n;++j) { if(height[i]>height[j]) { dp2[i]=max(dp2[i],dp2[j]+1); } } } int tmp=0; for(int i=1;i<n;++i) { for(int j=i+1;j<=n;++j) { if(dp[i]+dp2[j]>tmp) { tmp=dp[i]+dp2[j]; } } } printf("%d\n",n-tmp); return 0; }
相关文章推荐
- 详解Android应用中屏幕尺寸的获取及dp和px值的转换
- 基于Android中dp和px之间进行转换的实现代码
- Android中dip、dp、sp、pt和px的区别详解
- LFC1.0.0 版本发布
- Android dpi,dip,dp的概念以及屏幕适配
- Android px、dp、sp之间相互转换
- HP data protector软件学习1--基本角色与基本工作流程
- HP data protector软件学习2--软件组成与界面介绍
- android中像素单位dp、px、pt、sp的比较
- Android对px和dip进行尺寸转换的方法
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1001
- POJ ACM 1002
- 1611:The Suspects
- POJ1089 区间合并
- Android根据分辨率进行单位转换-(dp,sp转像素px)
- android 尺寸 dp,sp,px,dip,pt详解
- DP问题各种模型的状态转移方程
- POJ 2159 Ancient Cipher
- POJ 2635 The Embarrassed Cryptographe