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. diff工具

    Beyond Compare 4  可以diff文件夹.单个文件.

  2. 如何安装secureCRT8.1破解

    安装地址 网盘: https://pan.baidu.com/s/1iGxi6BTCMC_jewCwcUHhgA 密码: u6jq 安装教程 1.点击安装 2.全部默认即可,安装完成之后再桌面上右击该 ...

  3. (4.11)sql server内存使用

    一些内存使用错误理解   开篇小感悟 在实际的场景中会遇到各种奇怪的问题,为什么会感觉到奇怪,因为没有理论支撑的东西才感觉到奇怪,SQL Server自己管理内存,我们可以干预的方式也很少,所以日常很 ...

  4. Linux中vim命令出现E325错误解决方法

    出现该问题的原因是: vim在编辑文件的时候会创建一个swp file来保证文件的安全性,如果没有正常退出vim的,下次打开这个文件就会报E325的错误,提示swp文件已经存在. 解决方法也简单:把这 ...

  5. KGX滚动分页源码

    源码描述: 本工具采用Jquery框架,通过jquery调用ashx获取并输出数据,示例中采用测试数据,可以自行扩展为图片等等 当下流行的分页方式,鼠标滚动下拉条会自动展示下一页信息,类似瀑布流的效果 ...

  6. android 获取视频缩略图终极解决方案(ffmpeg)

    http://blog.csdn.net/u010499721/article/details/50338623 前些天有个师弟(在做一个仿LinkInEyes行车记录仪的app)问我怎么获取视频缩略 ...

  7. $.proxy() 的妙用

    $.proxy() 最主要就是用来修改函数执行时的上下文对象的. 先看以下情景: <div id="panel" style="display:none;" ...

  8. pagination结合ajax

    function getContent(page,Id){ $.ajax({ type:'get', url:'www.baidu.com', dataType:'jsonp', data:{ }, ...

  9. 原生javasxript获取浏览器的滚动距离和可视窗口的高度

    原生javasxript获取浏览器的滚动距离和可视窗口的高度 //封装兼容性方法获取滚动的距离 function getScrollOffset(){ if(window.pageXOffset){ ...

  10. 写时拷贝(Copy On Write)方案详解

    本文旨在通过对 写时拷贝 的四个方案(Copy On Write)分析,让大家明白写时拷贝的实现及原理. 关于浅拷贝与深拷贝,我在之前的博客中已经阐述过了  浅拷贝容易出现指针悬挂的问题,深拷贝效率低 ...