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 ;
}
 
 
 
 
 
 

poj 1836 LIS变形的更多相关文章

  1. 九度 1557:和谐答案 (LIS 变形)

    题目描述: 在初试即将开始的最后一段日子里,laxtc重点练习了英语阅读的第二部分,他发现了一个有意思的情况.这部分的试题最终的答案总是如下形式的:1.A;2.C;3.D;4.E;5.F.即共有六个空 ...

  2. hdu 1087(LIS变形)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  3. UVA 437 巴比伦塔 【DAG上DP/LIS变形】

    [链接]:https://cn.vjudge.net/problem/UVA-437 [题意]:给你n个立方体,让你以长宽为底,一个个搭起来(下面的立方体的长和宽必须大于上面的长和宽)求能得到的最长高 ...

  4. POJ 1836 Alignment 最长递增子序列(LIS)的变形

    大致题意:给出一队士兵的身高,一开始不是按身高排序的.要求最少的人出列,使原序列的士兵的身高先递增后递减. 求递增和递减不难想到递增子序列,要求最少的人出列,也就是原队列的人要最多. 1 2 3 4 ...

  5. POJ 1836-Alignment(DP/LIS变形)

    Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13465   Accepted: 4336 Descri ...

  6. POJ 1836 Alignment --LIS&LDS

    题意:n个士兵站成一排,求去掉最少的人数,使剩下的这排士兵的身高形成“峰形”分布,即求前面部分的LIS加上后面部分的LDS的最大值. 做法:分别求出LIS和LDS,枚举中点,求LIS+LDS的最大值. ...

  7. poj 1836 Alignment(dp)

    题目:http://poj.org/problem?id=1836 题意:最长上升子序列问题, 站队,求踢出最少的人数后,使得队列里的人都能看到 左边的无穷远处 或者 右边的无穷远处. 代码O(n^2 ...

  8. UVa 1471 (LIS变形) Defense Lines

    题意: 给出一个序列,删掉它的一个连续子序列(该子序列可以为空),使得剩下的序列有最长的连续严格递增子序列. 分析: 这个可以看作lrj的<训练指南>P62中讲到的LIS的O(nlogn) ...

  9. hdu5773--The All-purpose Zero(LIS变形)

    题意:给一个非负整数的数列,其中0可以变成任意整数,包括负数,求最长上升子序列的长度. 题解:LIS是最简单的DP了,但是变形之后T^T真的没想到.数据范围是10^5,只能O(nlogn)的做法,所以 ...

随机推荐

  1. 安装CentOS 7.4 可能会出现的坑以及解决方案

    安装CentOS 7.4 可能会出现的坑以及解决方案 (解决方法不唯一,如果行不通的话emmmm~~, 百度会啥你会啥~~) 坑.0X01 解决: 退出虚拟机,以管理员权限运行 坑.0X02 解决: ...

  2. 常用算法及其Python实现

    冒泡排序 ​ def bubble_sort(li):    for i in range(len(li)-1): # i表示第几趟        for j in range(len(li)-i-1 ...

  3. Hadoop权威指南读书笔记

    本书中提到的Hadoop项目简述 Common:一组分布式文件系统和通用I/O的组件与接口(序列化.javaRPC和持久化数据结构). Avro:一种支持高效.跨语言的RPC以及永久存储数据的序列化系 ...

  4. 字符串之strstr

    功能:查找第二个字符串是否存在第一个字符串中. 输入:字符串1,字符串2 返回值:成功返回str1中的位置,失败返回NULL #include <iostream> using names ...

  5. 剑指offer 面试25题

    面试25题:题目:合并两个排序的链表 题:输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则. 解题思路:递归,并需注意对空链表单独处理. 解题代码: # -* ...

  6. 在英文Windows操作系统上使用SQL Server Management Studio(SSMS)导入Excel 97-2003文件时报错:Failure creating file

    今天在公司服务器上使用SQL Server Management Studio(SSMS)导入Excel 97-2003文件(.xls)时报错: Failure creating file. (Mic ...

  7. range基础

    collapse这个方法是把结束位置抛弃掉,并不是简单的设置到开始位置. 结束位置被抛弃掉以后,只要没有给它重新设置位置,它就一直都会等 于开始位置.即使你修改了开始位置,结束位置还是会在修改后的开始 ...

  8. val() attr('value')

    val() 只能更改输入框内的值,能更改value属性, 在浏览器中体现不出value被改变 attr('value') 都可以 谷歌浏览器 val,attr都能获取输入框最新的value值

  9. Loadrunner之脚本篇——事务函数

    1.事务的开始和结束名称需要相同 lr_start_transaction(“transaction_name”); …//事务处理 lr_end_transaction(“transaction_n ...

  10. 试坑不完美的 clip-path (我说的 CSS 的那个)

    需求跟我说,咱们要创新,想做一个蜂巢状的列表,年少无知的我竟然一口答应了,全然因为刚接触了 clip-path: But,然而,不幸的是,这只是坎坷路途的开始.... clip-path 的教程很多了 ...