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 ... 
随机推荐
- PC端的混合应用通讯问题
			exe使用C#开发,内嵌HTML页面HTML页面与exe程序的通讯方式可以使用以下方式: HTML通知exe:C#有个titlechange事件,可以监听内部HTML的title,那么HTML就可以通 ... 
- 论文笔记之:Deep Reinforcement Learning with Double Q-learning
			Deep Reinforcement Learning with Double Q-learning Google DeepMind Abstract 主流的 Q-learning 算法过高的估计在特 ... 
- jQuery序列化后的表单值转换成Json
			$.fn.serializeObject = function() { var o = {}; var a = this.serializeArray(); $.each(a, function() ... 
- Questions?
			http://www.datastax.com/wp-content/themes/datastax-2014-08/files/NoSQL_Benchmarks_EndPoint.pdf http: ... 
- 100 open source Big Data architecture papers for data professionals
			zhuan :https://www.linkedin.com/pulse/100-open-source-big-data-architecture-papers-anil-madan Big Da ... 
- 靠边伸缩菜单的做法(类似QQ,碰到就会伸出来)
			这段脚本主要实现一个group的伸缩功能,group里面的内容也就是菜单的内容可以自由添加. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ... 
- Xcode 7  ImageNamed 方法加载jpg图片失败
			更新XCode7后 原来的Image.xcassets文件夹变成了Assets.xcassets 把01.jpg,02.jpg,03.png拖入这个文件夹中 UIImage* test1=[UIIma ... 
- SQL Server 索引分类
			什么是索引 拿汉语字典的目录页(索引)打比方:正如汉语字典中的汉字按页存放一样,SQL Server中的数据记录也是按页存放的,每页容量一般为4K .为了加快查找的速度,汉语字(词)典一般都有按拼音. ... 
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)转
			互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,Dubbo是一个分布式服务框架,在这种情况下诞生的.现在核心业务抽取出来,作为独立的服务,使 ... 
- PorterDuff.Mode error
			Android PorterDuff.Mode error: PorterDuff cannot be resolved to a variable Answers: Add this t ... 
