cf 605A Sorting Railway Cars 贪心 简单题
其实就是求总长度 - 一个最长“连续”自序列的长度
最长“连续”自序列即一个最长的lis,并且这个lis的值刚好是连续的,比如4,5,6...
遍历一遍,贪心就是了
遍历到第i个时,此时值为a[i],如果a[i]-1在前面已经出现过了,则len[a[i]] = len[a[i-1]]+1
否则len[a[i]] = 1
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream> using namespace std; const int MAXN = +; bool pos[MAXN];
int len[MAXN]; void solve()
{
int n;
scanf("%d",&n);
memset(pos,false,sizeof pos);
for(int i=;i<=n;i++){
int a;
scanf("%d",&a);
if(pos[a - ]){
len[a] = len[a-] + ;
}
else{
len[a] = ;
}
pos[a] = true;
} int ma = -;
for(int i=;i<=n;i++){
if(len[i] > ma)
ma = len[i];
} printf("%d\n",n - ma);
return ;
} int main()
{
solve();
return ;
}
cf 605A Sorting Railway Cars 贪心 简单题的更多相关文章
- CF#335 Sorting Railway Cars
Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- CodeForces 605A Sorting Railway Cars 思维
早起一水…… 题意看着和蓝桥杯B组的大题第二道貌似一个意思…… 不过还是有亮瞎双眼的超短代码…… 总的意思呢…… 就是最长增长子序列且增长差距为1的的…… 然后n-最大长度…… 这都怎么想的…… 希望 ...
- CodeForces 605A Sorting Railway Cars
求一下最长数字连续上升的子序列长度,n-长度就是答案 O(n)可以出解,dp[i]=dp[i-1]+1,然后找到dp数组最大的值. #include<cstdio> #include< ...
- CodeForces 606C--Sorting Railway Cars,思路题~~~
C - Sorting Railway Cars Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d &am ...
- Codeforces Round #335 (Div. 2) C. Sorting Railway Cars 连续LIS
C. Sorting Railway Cars An infinitely long railway has a train consisting of n cars, numbered from ...
- Codeforces Round #335 (Div. 2) C. Sorting Railway Cars 动态规划
C. Sorting Railway Cars Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/conte ...
- A. Sorting Railway Cars
A. Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces 606-C:Sorting Railway Cars(LIS)
C. Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #335 (Div. 2) C. Sorting Railway Cars
C. Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- 创建kafkatopic和productor
cd 到kafka 目录下 创建topic create topicbin/kafka-topics.sh --zookeeper spark1:2181,spark2:2181,spark3:218 ...
- 黑马程序员——JAVA基础之单列设计模式
------- android培训.java培训.期待与您交流! ---------- 单列设计模式是面试中的一个常考的点,所谓单例模式就是说对象在内存中只能存在一个.如果有其他变量是该类对象,那么他 ...
- Learn python the hard way. python test program 2016.04.27
# this will not be printed in python ! print "I could have code like this." # and the comm ...
- Opencv 3入门(毛星云)摘要
第一章 环境搭建: 1. 环境变量path 添加 D:\Program Files\opencv\build\x86\vc11\bin 2. VS在VC++项目中,属性管理器\属性. VC++目 ...
- error LNK2026: 模块对于 SAFESEH 映像是不安全的
解决方法: 1.打开该项目的“属性页”对话框. 2.单击“链接器”文件夹. 3.单击“命令行”属性页. 4.将 /SAFESEH:NO 键入“附加选项”框中,然后点击应用.
- PHP使用Mysql事务
<?php //数据库连接 $conn = mysql_connect('localhost', 'root', ''); mysql_select_db('test', $conn); mys ...
- linux服务之rsync
http://www.cnblogs.com/itech/archive/2010/06/13/1757952.html rsync与mfs好像有点类似,都是传输块的chunk,chunk的 1)软件 ...
- Storyboard 跳转 和 传值
因为苹果推 Storyboard 而且 目前来看, Apple Watch 也是用 Storyboard 就知道, 明天应用估计都是 Storyboard 的天下了. (水平有限, 不对之处在所难免, ...
- dubbo Linux 解决:nc: command not found
出现该情况有两种可能: (1)没有配置nc命令的环境变量: (2)该系统没有安装nc命令: 我查看了一下在/usr/bin目录中并没有nc命令,所以我可以认为出现该情况的原因是第二种情况 下载安装 下 ...
- javascript 返回数组中不重复的元素
这是实现结构伪类type-of-type的部分代码: <script type="text/javascript"> var ret= ["span" ...