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

最长“连续”自序列即一个最长的lis,并且这个lis的值刚好是连续的,比如4,5,6...

遍历一遍,贪心就是了

遍历到第i个时,此时值为a[i],如果a[i]-1在前面已经出现过了,则len[a[i]] = len[a[i-1]]+1

否则len[a[i]] = 1

  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <cstring>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. const int MAXN = +;
  9.  
  10. bool pos[MAXN];
  11. int len[MAXN];
  12.  
  13. void solve()
  14. {
  15. int n;
  16. scanf("%d",&n);
  17. memset(pos,false,sizeof pos);
  18. for(int i=;i<=n;i++){
  19. int a;
  20. scanf("%d",&a);
  21. if(pos[a - ]){
  22. len[a] = len[a-] + ;
  23. }
  24. else{
  25. len[a] = ;
  26. }
  27. pos[a] = true;
  28. }
  29.  
  30. int ma = -;
  31. for(int i=;i<=n;i++){
  32. if(len[i] > ma)
  33. ma = len[i];
  34. }
  35.  
  36. printf("%d\n",n - ma);
  37. return ;
  38. }
  39.  
  40. int main()
  41. {
  42. solve();
  43. return ;
  44. }

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. P188 实战练习(父类和子类)

    1.创建一个父类,在父类中创建两个方法,在子类中覆盖第二个方法,为子类创建一个对象,将它向上转型到基类并调用这个方法. 创建Computer父类: package org.hanqi.practise ...

  2. 黑马程序员——JAVA基础之多态与Object

    ------- android培训.java培训.期待与您交流! ----------  多态 : 多态定义:  某一类事物的多种存在形态. 多态的体现: 父类的引用指向了自己的子类对象.       ...

  3. 一些实用的JS

    1.str.split(/\s+/) 这句是表示以和/\s+/匹配的字符串作为分界,分割字符串str 比如一个空格或者多个或者空格以及回车等  其中+表示一个或者多个 var a = "b- ...

  4. (转)A Beginner's Guide To Understanding Convolutional Neural Networks

    Adit Deshpande CS Undergrad at UCLA ('19) Blog About A Beginner's Guide To Understanding Convolution ...

  5. javascript闭包实例

    实例一 //每次执行一次c()i加1.关键在于var c=a():c容器将i装载记住了. function a(){ var i=0; function b(){ alert(++i); } retu ...

  6. centos6.4 网络适配器设置仅主机模式

    网络适配器设置仅主机模式时: 1.vmnet1网卡必须开启

  7. linux -redhat rpm 和zabbix和各种rpm包下载地址

    redhat ftp://ftp.redhat.com/pub/redhat/linux/enterprise/6Client/en/os/SRPMS/ zabbix https://sourcefo ...

  8. 【转载】关于Python中的yield

    在介绍yield前有必要先说明下Python中的迭代器(iterator)和生成器(constructor). 一.迭代器(iterator) 在Python中,for循环可以用于Python中的任何 ...

  9. redis模块

    http://www.cnblogs.com/melonjiang/p/5342505.html http://www.django-china.cn/topic/1054/ 1.连接方式 redis ...

  10. javascript this 代表的上下文,JavaScript 函数的四种调用形式

    JavaScript 是一种脚本语言,支持函数式编程.闭包.基于原型的继承等高级功能.其中JavaScript 中的 this 关键字,就是一个比较容易混乱的概念,在不同的场景下,this会化身不同的 ...