poj 1836 LIS变形
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 17331 | Accepted: 5694 |
Description
Write a program that, knowing the height of each soldier, determines
the minimum number of soldiers which have to get out of line.
Input
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
Sample Input
8
1.86 1.86 1.30621 2 1.4 1 1.97 2.2
Sample Output
4
Source
#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变形的更多相关文章
- 九度 1557:和谐答案 (LIS 变形)
题目描述: 在初试即将开始的最后一段日子里,laxtc重点练习了英语阅读的第二部分,他发现了一个有意思的情况.这部分的试题最终的答案总是如下形式的:1.A;2.C;3.D;4.E;5.F.即共有六个空 ...
- hdu 1087(LIS变形)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- UVA 437 巴比伦塔 【DAG上DP/LIS变形】
[链接]:https://cn.vjudge.net/problem/UVA-437 [题意]:给你n个立方体,让你以长宽为底,一个个搭起来(下面的立方体的长和宽必须大于上面的长和宽)求能得到的最长高 ...
- POJ 1836 Alignment 最长递增子序列(LIS)的变形
大致题意:给出一队士兵的身高,一开始不是按身高排序的.要求最少的人出列,使原序列的士兵的身高先递增后递减. 求递增和递减不难想到递增子序列,要求最少的人出列,也就是原队列的人要最多. 1 2 3 4 ...
- POJ 1836-Alignment(DP/LIS变形)
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 13465 Accepted: 4336 Descri ...
- POJ 1836 Alignment --LIS&LDS
题意:n个士兵站成一排,求去掉最少的人数,使剩下的这排士兵的身高形成“峰形”分布,即求前面部分的LIS加上后面部分的LDS的最大值. 做法:分别求出LIS和LDS,枚举中点,求LIS+LDS的最大值. ...
- poj 1836 Alignment(dp)
题目:http://poj.org/problem?id=1836 题意:最长上升子序列问题, 站队,求踢出最少的人数后,使得队列里的人都能看到 左边的无穷远处 或者 右边的无穷远处. 代码O(n^2 ...
- UVa 1471 (LIS变形) Defense Lines
题意: 给出一个序列,删掉它的一个连续子序列(该子序列可以为空),使得剩下的序列有最长的连续严格递增子序列. 分析: 这个可以看作lrj的<训练指南>P62中讲到的LIS的O(nlogn) ...
- hdu5773--The All-purpose Zero(LIS变形)
题意:给一个非负整数的数列,其中0可以变成任意整数,包括负数,求最长上升子序列的长度. 题解:LIS是最简单的DP了,但是变形之后T^T真的没想到.数据范围是10^5,只能O(nlogn)的做法,所以 ...
随机推荐
- 基于Cpython的 GIL(Global Interpreter Lock)
一 介绍 定义: In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native t ...
- MySQL root用户忘记密码怎么办?修改密码方法:skip-grant-tables
忘记密码怎么办? 1.以管理员身份打开cmd2.执行命令tasklist |findstr mysql ,查看正在运行的mysql进程 3.执行命令taskkill /F /PID 13644(此处进 ...
- NodeJS的一些总结
NodeJS的一些总结 Node 公开宣称的目标是 “旨在提供一种简单的构建可伸缩网络程序的方法”. 当前的服务器程序有什么问题?我们来做个数学题. 在 Java™ 和 PHP 这类语言中,每个连接都 ...
- android学习一---搭建开发环境
android基于Java并运行Linux内核上的轻量级操作系统.由于是基于java的,学习起来也不是太难,对java有一定了解并知道一些基本的图形用户界面,入门就很简单了. 一.了解JDK ,SDK ...
- 交叉熵(Cross-Entropy) [转载]
交叉熵(Cross-Entropy) 交叉熵是一个在ML领域经常会被提到的名词.在这篇文章里将对这个概念进行详细的分析. 1.什么是信息量? 假设X是一个离散型随机变量,其取值集合为X,概率分布函数为 ...
- php会话技术之Session用法
php会话技术之Session用法举例. 本文原始链接:http://www.jbxue.com/article/8940.html1.创建session <?php //创建sessi ...
- python操作——RabbitMQ
RabbitMQ是一个在AMQP基础上完整的,可服用的企业消息系统.他遵循Mozilla Public License开源协议. MQ全称为Message Queue,消息队列(MQ)是一种应用程序对 ...
- django 操作前端数据
django 利用json处理前端页面数据,FLASK当中也同样 def create_company(request):if request.user.is_superuser:custom_l ...
- Nginx常用命令(加入系统服务)
nginx 服务器重启命令,关闭 nginx -s reload :修改配置后重新加载生效 nginx -s reopen :重新打开日志文件 nginx -t -c /path/to/nginx.c ...
- php分类树
class Category{ public $sonName; public $parentName; public function __consturt($id,$parent_id){ $th ...