POJ - 1836 Alignment

基于深度视觉实现机械臂对目标的识别与定位 Marker ID 和 Marker size 自选,在 launch 文件中做相应的修改(本教程演示使用 Marker ID:582,Marker size:30mm)根据相机和机械臂的安装方式不同,手眼标定分为眼在手上和眼在手外两种方式,双臂机器人的相机和机械臂基座的相对位置固定,所以应该采用眼在手外的手眼标定方式。后续的视觉引导机械臂抓取测试实验基于本实验实现,通过视觉引导右臂完成抓取目标物,所以默认已使用机械臂右臂和相机完成了手眼标定。文件,根据打印的marker 标签,需要配置。 阅读详情

Alignment
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 16494 Accepted: 5406

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

题意是从原序列中移走几个士兵,得到一个新的序列,且这个序列满足  每个士兵向左或向右至少一个方向都不存在比他高或和他一样高的

要求最少移走几个人

从前到后求一遍最长递增子序列,在从后到前求一遍

因为数据不大,最后两层for循环遍历求出最大值

又错在了忘记了dp【i】并非前i个的最长递增子序列长度,而应该是dp【1~i】里的最大值,所以最后只用了一层for循环遍历,谨记!

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
int main()
{	
	int n,dp[2000],dp1[2000],i,j,ans;
	double k[2000];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%lf",&k[i]);
	for(i=0;i<n;i++)
	dp[i]=1,dp1[i]=1;
	for(i=1;i<n;i++)
	{
		for(j=0;j<i;j++)
		{
			if(k[i]>k[j])
			dp[i]=max(dp[i],dp[j]+1);
		}
	}
	for(i=n-1;i>=0;i--)
	{
		for(j=n-1;j>i;j--)
		{
			if(k[i]>k[j])
			dp1[i]=max(dp1[i],dp1[j]+1);
		}
	}
	ans=dp[0]+dp1[0]-1;
	for(i=0;i<n;i++)
	for(j=i+1;j<n;j++)
	ans=max(ans,dp[i]+dp1[j]);
	
	for(i=1;i<n;i++)
	ans=max(ans,dp[i]+dp1[j]-1);
	printf("%d\n",n-ans);
	return 0;
 }


【100%通过率】华为od机试C卷【部门人力分配】Python 实现 当前部门需要完成 N 个需求,需求用 requirements[i] 表示,requirements[i] 表示第 i 个需求的工作量大小,单位:人月。2:明显这个人力需求值有上下限的情况下【下限为requirements中的最大值,上限为requirements中的最大两个值相加(因为最多有两个需求同一个月开发)】,可以考虑使用二分法。当选择人力为6时,2个需求量为3的工作可以在1个月里完成,其他2个工作各需要1个月完成。当选择人力为5时,4个工作各需要1个月完成,一共需要4个月才能完成所有需求。 阅读详情

相关推荐

银河麒麟V10+QT6.0中文输入法环境搭建全攻略(附镜像加速技巧)

本文提供了在银河麒麟V10操作系统上为QT6.0搭建中文输入法环境的完整实战指南。文章详细介绍了从系统准备、镜像源优化、QT6安装器获取与加速安装,到编译Fcitx5输入法插件依赖库、深度配置环境变量与项目的全流程。重点分享了使用国内镜像源加速安装的技巧,解决了国产化开发中QT应用无法输入中文的常见难题,旨在帮助开发者快速构建稳定高效的开发环境。

weixin_29204749的博客 393

ACM: 最长升序和最长降序 dp题 poj…

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

smile_benson 508

银河麒麟v10(x86_64)升级openssh实操成功

本文详细介绍了在银河麒麟V10系统上将OpenSSH从8.2p1升级至9.9p2版本的全过程。主要内容包括:系统环境确认、安装telnet备用连接、备份配置、卸载旧版本、安装新版本、服务配置与验证等关键步骤。特别强调了安全注意事项,如必须安装telnet作为备用连接、重要配置备份等。升级后提供了安全加固建议,包括修改SSH端口、禁用root登录等。文章还包含详细的故障排查方法和恢复方案,确保升级过程安全可靠。通过本教程,用户可以顺利完成OpenSSH版本升级,提升系统安全性。

淘淘小窝 1089

Alignment(POJ--1836

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 t

zhang_di233的专栏 448

计算机组成原理汉字编码与校验设计实验报告(汉字国标码转区位码实验、汉字机内码获取实验、海明编码电路设计与海明解码)

这次实验利用logisim进行设计,进行了以下这四个实验,其中分为汉字国标码转区位码实验、汉字机内码获取实验、海明编码电路设计与海明解码,实验报告分为四个部分,在这四个部分中依次对四个实验的方案设计,设计思路进行了介绍

zhang2gongzi的博客 6万+

SAP 银企直连实战:从零构建 DMEEX 格式树的配置与调试指南

本文详细介绍了SAP银企直连中DMEEX格式树的配置与调试方法,涵盖从基础认知到实战技巧的全流程。通过具体案例解析,帮助财务顾问快速掌握建设银行付款报文的格式树搭建、字段映射及调试优化,提升企业支付效率与准确性。

weixin_42526015的博客 566

1poj1836(和合唱队列一样)

http://poj.org/problem?id=1836 Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 9110 Accepted: 2859 Description In the army, a platoon is composed by n soldiers. During

ZhouRush 1886

腾讯云CodeBuddy+微信小程序:5分钟开发番茄小闹钟

番茄钟是一种简单的时间管理方法。这个方法很简单:你专注工作25分钟,然后休息5分钟。这样可以让你更专心,不容易分心,还能防止过度疲劳。 很多人用番茄钟来提高工作效率,因为它能帮助你更好地管理时间。不过,市面上的一些免费番茄钟应用常常会有广告弹出来,影响使用体验。这就是为什么我们要开发一个没有广告的番茄钟小程序,让用户可以专心工作,不被打扰。

2201_75366661的博客 1689

[DP]poj1836

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

zylm的专栏 527

【论文汇总】Diffusion Models视频生成/视频编辑/可控视频生成/跨模态视频生成

本文总结了Diffusion Models视频生成领域相关的工作,目前共收录142篇,持续更新中。

沉迷单车的追风少年 1672

Win7/10/11文件拖拽导致资源管理器闪退问题

最近老是遇到把文件从资源管理器拖动到微信或者浏览器时,资源管理器直接闪退的问题,一开始在公司遇到了还以为是电脑配置太低,直到被封闭在家办公,发现自己的高级电脑也有这个问题,那就来了解了解问题是出在什么地方把。

Nicer_feng's blog 1万+

【POJ 1836】 Alignment

【POJ 1836】 Alignment有一队士兵 已知每个士兵个头 想要从中选一些士兵出列 让剩下的士兵向左或向右能看到队首(及左边或右边的士兵个头都< 他) 两次LIS 从左往右 从右往左分别LIS 然后枚举找最少出队人数即可代码如下:#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #de

ACMer' 1050

高级数据库--作业及答案

中科大金培权老师的高级数据库课程作业及答案

一杯水果茶!足矣~ 1657

[POJ 1836]Alignment[DP][LIS]

题目链接:[POJ 1836]Alignment[DP][LIS] 题意分析: 为了使得士兵的队列满足:任意一个士兵都能看到他前方的无穷远处或者后方的无穷远处(大概是个三角形的样子)。最少需要移出去多少名士兵? 解题思路: 求出原序列的最长上升和最长下降子序列,然后枚举左右士兵即可。 个人感受: 怎么枚举士兵这点没处理好,之前思维卡在三角形只有一个最高点,其实本题并非完全让队列变成三角

闲停 481

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

poj 1836 Alignment 排队

poj 1836 Alignment http://poj.org/problem?id=1836 题意:有士兵n个,根据编号排为一列,但是身高不一,现在要求去掉几个人,使得剩下的每一个人可以向左或向右看到队头。问:至少去掉的士兵数。 dp动态规划 之 双向LIS问题 1 /* 2 Problem: 1836 User:...

aidibi1469的博客 133

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

POJ 1836 Alignment - (DP)

题目链接:http://poj.org/problem?id=1836#include &lt;stdio.h&gt; #include &lt;vector&gt; #include &lt;algorithm&gt; using namespace std; //POJ 1836 Alignment int main() { int n; scanf("%d", &amp;n...

rsy56640的博客 204

POJ 1836 Alignment 双向LIS+DP

POJ 1836 Alignment题目描述:  题目链接:POJ 1836 Alignment题目大意:  令到原队列的最少士兵出列后,使得新队列任意一个士兵都能看到左边或者右边的无穷远处,且除最高点外任一士兵旁边不能存在等高的士兵。图来自http://blog.youkuaiyun.com/lyy289065406/article/details/6648129解题思路:  大致的想法就是分别做两个LIS(

Running Boy的AC Dream 487

POJ 1836 Alignment DP LIS

传送门:POJ1836 题意:有n个人站成一排,给出他们的身高,让其中某些人出列,要保证剩下的人能看到左边或右边的排头,问最少出队人数是多少。 思路:刚看题的时候理解错了题意,还以为剩下的人只能看向同一边,心想这不就是个裸LIS么。。结果还是我太年轻啊。。 其实剩下人的身高可以是这样:1 2 3 2 1  或者这样: 1 2 3 3 2 1   正确解法:正向和反向做LIS,然后记录每个点

WA是一笔财富 326

【最长下降子序列+有难度】北大 poj 1836 Alignment

/* THE PROGRAM IS MADE BY PYY */ /*----------------------------------------------------------------------------// Copyright (c) 2012 panyanyany All rights reserved. URL : http://poj.org/pr...

网站开发初中级代码参考-转载 153

POJ 1836 Alignment

Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9788   Accepted: 3107 Description In the army, a platoon is composed by n soldiers. During the mornin

ACM2272902662的专栏 934

POJ1836——Alignment

Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13366   Accepted: 4296 Description In the army, a platoon is composed by n soldiers. During the morni

Alex 1266

poj 1836 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 s

Vision 419

POJ 1836 Alignment LIS变形(最长上升子序列)

POJ 1836 Alignment    LIS变形(最长上升子序列) 题意:给 n 个数然后 让你求至少删除多少个数使剩下的数 可以满足在自己的位子上可以看到最左边或最右边的人 看到最边上人 的条件是某一边上的人都比自己矮 思路: 这道题是 LIS 的变形只需要求出 在每个位置上的 左边的最长上升子序列个数 加上 右边的最长下降子序列的个数 最后 n - 去他们就可以了 #in

became_a_wolf的专栏 426

poj 1836 Alignment

题目链接:http://poj.org/problem?id=1836 题目大意:将一队人的身高构成三角形,类似于1 2 3 2 1这样的,但是1 2 2 1也可以,方法就是分别从两侧进行dp求最长升序子序列,然后求最长的。。 AC代码: #include double h[1005],tall[1005],shor[1005],r[1005],l[1005]; int main()

黑山老猴妖的专栏 811

POJ 1836 Alignment

令到原队列的最少士兵出列后,使得新队列任意一个士兵都能看到左边或者右边的无穷远处。

AC__GO的博客 317

POJ 1836, Alignment

Time Limit: 1000MSMemory Limit: 30000KTotal Submissions: 3283Accepted: 963 DescriptionIn the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in ...

weixin_33757911的博客 281

POJ1836-Alignment

全解题报告索引目录 -> 【北大ACM – POJ试题分类】 转载请注明出处:http://exp-blog.com ------------------------------------------------------------------------- 解题思路:是POJ2533的扩展题。 题意不难,令到原队列的最少士兵出列后,使得新队列任意一个士兵都能看到左...

ζёСяêτ - 小優YoU 6959
上一篇: POJ - 1942 D - Paths on a Grid 组合数
下一篇: POJ - 1276 Cash Machine 多重背包模板题
jerans
博客等级 码龄10年 54粉丝 255原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值