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. 基于Cpython的 GIL(Global Interpreter Lock)

    一 介绍 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native t ...

  2. MySQL root用户忘记密码怎么办?修改密码方法:skip-grant-tables

    忘记密码怎么办? 1.以管理员身份打开cmd2.执行命令tasklist |findstr mysql ,查看正在运行的mysql进程 3.执行命令taskkill /F /PID 13644(此处进 ...

  3. NodeJS的一些总结

    NodeJS的一些总结 Node 公开宣称的目标是 “旨在提供一种简单的构建可伸缩网络程序的方法”. 当前的服务器程序有什么问题?我们来做个数学题. 在 Java™ 和 PHP 这类语言中,每个连接都 ...

  4. android学习一---搭建开发环境

    android基于Java并运行Linux内核上的轻量级操作系统.由于是基于java的,学习起来也不是太难,对java有一定了解并知道一些基本的图形用户界面,入门就很简单了. 一.了解JDK ,SDK ...

  5. 交叉熵(Cross-Entropy) [转载]

    交叉熵(Cross-Entropy) 交叉熵是一个在ML领域经常会被提到的名词.在这篇文章里将对这个概念进行详细的分析. 1.什么是信息量? 假设X是一个离散型随机变量,其取值集合为X,概率分布函数为 ...

  6. php会话技术之Session用法

    php会话技术之Session用法举例. 本文原始链接:http://www.jbxue.com/article/8940.html1.创建session <?php     //创建sessi ...

  7. python操作——RabbitMQ

    RabbitMQ是一个在AMQP基础上完整的,可服用的企业消息系统.他遵循Mozilla Public License开源协议. MQ全称为Message Queue,消息队列(MQ)是一种应用程序对 ...

  8. django 操作前端数据

    django 利用json处理前端页面数据,FLASK当中也同样   def create_company(request):if request.user.is_superuser:custom_l ...

  9. Nginx常用命令(加入系统服务)

    nginx 服务器重启命令,关闭 nginx -s reload :修改配置后重新加载生效 nginx -s reopen :重新打开日志文件 nginx -t -c /path/to/nginx.c ...

  10. php分类树

    class Category{ public $sonName; public $parentName; public function __consturt($id,$parent_id){ $th ...