其实就是求总长度 - 一个最长“连续”自序列的长度

最长“连续”自序列即一个最长的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 贪心 简单题的更多相关文章

  1. CF#335 Sorting Railway Cars

    Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  2. CodeForces 605A Sorting Railway Cars 思维

    早起一水…… 题意看着和蓝桥杯B组的大题第二道貌似一个意思…… 不过还是有亮瞎双眼的超短代码…… 总的意思呢…… 就是最长增长子序列且增长差距为1的的…… 然后n-最大长度…… 这都怎么想的…… 希望 ...

  3. CodeForces 605A Sorting Railway Cars

    求一下最长数字连续上升的子序列长度,n-长度就是答案 O(n)可以出解,dp[i]=dp[i-1]+1,然后找到dp数组最大的值. #include<cstdio> #include< ...

  4. CodeForces 606C--Sorting Railway Cars,思路题~~~

    C - Sorting Railway Cars   Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d &am ...

  5. 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 ...

  6. 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 ...

  7. A. Sorting Railway Cars

    A. Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. POJ3352 Road Construction(边双连通分量)

                                                                                                         ...

  2. Python笔记本

    Python 的主提示符( >>> )和次提示符( ... ).主提示符是解释器告诉你它在等你输入下一个语句,次提示符告诉你解释器正在等待你输入当前语句的其它部分. 下划线(_)在解 ...

  3. Java——函数

     ------- <a href="http://www.itheima.com" target="blank">android培训</a ...

  4. c++语法集锦

    1.指针的引用 他也是引用,引用是特定内存块的别名 2.变量定义 更准确的说是内存使用约定,并为该约定命名 命名3.指向常变量的指针和常指针 有点拗口,都是指针,但对于所在内存块的使用约定不同.常变量 ...

  5. Oracle 12c RAC 搭建手册

    1  共享设备配置 1.1            设备划分说明 冗余策略 卷划分及大小说明 OCRVOTING Ocrvoting01 8G Ocrvoting02 8G Ocrvoting03 8G ...

  6. 利用C#Marshal类实现托管和非托管的相互转换

    Marshal 类 命名空间:System.Runtime.InteropServices 提供了一个方法集,这些方法用于分配非托管内存.复制非托管内存块.将托管类型转换为非托管类型,此外还提供了在与 ...

  7. jquery ajax POST 例子详解

    function test(){ $.ajax({ //提交数据的类型 POST GET type:"POST", //提交的网址 url:"testLogin.aspx ...

  8. Android开发常用的一些第三方网站

    聚合数据-免费数据调用 https://www.juhe.cn/ 有赞- 免费的微商城 http://youzan.com/ 秀米微信图文编辑器 http://xiumi.us/ 禅道项目管理软件 h ...

  9. Entity Framework的核心 – EDM(Entity Data Model) 一

    http://blog.csdn.net/wangyongxia921/article/details/42061695 一.EnityFramework EnityFramework的全程是ADO. ...

  10. Js RegExp对象

    1 语法 1.1 直接量语法 /pattern/attributes 1.2 创建RegExp对象 new RegExp(pattern, attributes) 1.3 说明 pattern是正则表 ...