题目

一个长度为 \(n\) 的排列,每次可以将一个数移至开头或者结尾,问最少多少次使其升序排列


分析

让数字连续的情况尽量多才能让移出来的次数尽量少,

找到最长的数字连续段,若其长度为 \(len\),那么答案为 \(n-len\)


代码

#include <cstdio>
#include <cctype>
using namespace std;
int n,ans,las[100011],f[100011];
int iut(){
int ans=0; char c=getchar();
while (!isdigit(c)) c=getchar();
while (isdigit(c)) ans=ans*10+c-48,c=getchar();
return ans;
}
int max(int a,int b){return a>b?a:b;}
int main(){
n=iut();
for (int i=1;i<=n;++i){
int x=iut();
if (las[x-1]) f[i]=f[las[x-1]]+1;
else f[i]=1;
ans=max(ans,f[i]),las[x]=i;
}
return !printf("%d",n-ans);
}

#贪心#CF605A Sorting Railway Cars的更多相关文章

  1. CF605A Sorting Railway Cars(递推)

    题目描述 An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers ...

  2. CF605A Sorting Railway Cars

    传送门 题目大意 给出一个 1 到 n 的排列,每次操作可以将某个位置的数字移动到最前面或最后面,求将排列从小到大排序的最小操作次数 如:4 1 2 5 3 操作1:将5和3换一下变成4 1 2 3 ...

  3. CF605A Sorting Railway Cars 题解

    To CF 这道题依题意可得最终答案为序列长度-最长子序列长度. 数据范围至 \(100000\) 用 \(O(n^2)\) 的复杂度肯定会炸. 用 \(O(nlogn)\) 的复杂度却在第 \(21 ...

  4. CF#335 Sorting Railway Cars

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

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

  10. Codeforces 335C Sorting Railway Cars

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

随机推荐

  1. win32-使用FillRect绘制具有渐变颜色的客户区域背景

    void OnEraseBkGnd(HWND hwnd) { /* Vars */ HDC dc; /* Standard Device Context; used to do the paintin ...

  2. [BUUCTF][Web][ACTF2020 新生赛]Exec 1

    打开靶机对应url 显示可以输出ip 来进行ping操作 尝试试一下是否有命令注入的可能 127.0.0.1|ls 果然可以,输出结果 index.php PING 127.0.0.1 (127.0. ...

  3. day06---基础优化之防火墙,yum源,字符集,vim补充,echo命令

    1.系统版本号 cat /etc/redhat-release hostnamectl uname -r 2.系统 时间硬件时间 date hwclock clock hwclock systohc ...

  4. 【Azure 云服务】云服务(经典)迁移到云服务(外延支持)的八个问题

    问题一:云服务( 经典)迁移到外延支持云服务是否需要停机? 通过平台的迁移工具(即验证.准备.提交)进行迁移没有停机时间.但是如果需要准备满足迁移条件,如删除对等互联,使用其他vnet资源则需要额外的 ...

  5. 【Azure 环境】前端Web通过Azure AD获取Token时发生跨域问题(CORS Error)

    问题描述 前端Web在开发时使用Azure AD中注册Application的方式进行Token获取,遇到了CORS遇到的问题(如下图).随后在AAD增加了单页应用的重定向URL, 依旧还是出现COR ...

  6. 【Filament】材质系统

    1 前言 ​ 本文主要介绍 Filament 的材质系统,官方介绍详见 → Filament Materials Guide.材质系统中会涉及到一些空间和变换的知识点,可以参考:[Unity3D]空间 ...

  7. 链接服务器导致SQL Server停止响应

    概要 如果多个实例中同时存在数据源为对方实例的链接服务器,并且开启了"分发服务器"的属性,您可能会遇到这种情况. 1 现象 14:31时,在SSMS中检查HIS实例是否有复制订阅时 ...

  8. nginx rewrite 语法

    nginx rewrite 语法 一 定义 Rewrite主要实现url地址重写, 以及地址重定向,就是将用户请求web服 务器的地址重新定向到其他URL的过程. 二 语法格式 reweite fia ...

  9. Kubernetes-一文详解ServiceAccount与RBAC权限控制

    一.ServiceAccount 1.ServiceAccount 介绍 首先Kubernetes中账户区分为:User Accounts(用户账户) 和 Service Accounts(服务账户) ...

  10. aardio 背景透明的3种方式(透明窗体1 webview2,透明窗体2-win-region-bitmap,透明窗体3-winform-transparent-color)

    aardio 背景透明的3种方式(透明窗体1 webview2,透明窗体2-win-region-bitmap,透明窗体3-winform-transparent-color) 3种透明窗体,主要分成 ...