题目大意

给你一个1~n的排列

你有两个操作:将一个数移到最后或将一个数移到最前

问将排列排序最少要几次操作

分析

年纪大了,脑子不行了..

实际我们只需求出对与一段连续的数它在排列中已经有序的最长长度即可

剩下的数暴力放到最前/最后即可

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int pl[];
int main(){
int n,m,i,j,k,ans=,len=;
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d",&k);
pl[k]=i;
}
for(i=;i<n;i++)
if(pl[i+]>pl[i])len++;
else ans=max(ans,len),len=;
ans=max(ans,len);
cout<<n-ans<<"\n";
return ;
}

AGC024B Backfront的更多相关文章

  1. 剑指offer编程题java实现(正在更新)

    面试题三:查找二维数组中元素问题 public static void main(String[] args){ int[][] num = {{1,2,8,9},{2,4,9,12},{4,7,10 ...

  2. 由python为入口回顾C++的lambda

    lambda是一种匿名函数,python  lambda可以使简单的函数简洁的表达,,C++的lambda使类似嵌套函数的功能得以实现 python的lambda lambda [arg1[,arg2 ...

  3. C#解leetcode 18. 4Sum

    Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = tar ...

  4. 【AtCoder】AGC024

    A - Fairness 如果奇数次是b - a 否则是a - b #include <bits/stdc++.h> #define fi first #define se second ...

  5. 57 和为S的数字

    题目一:和为S的两个数字 输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 输出描述: 对应每个测试案例,输出两个数,小 ...

  6. APUE之第5章——标准I/O库

    一.知识回顾:文件I/O 文件 I/O 是不带缓冲的 I/O(unbuffered I/O),指每个 read 和 write 都调用内核中的一个系统调用. 对于内核而言,所有打开的文件都通过文件描述 ...

随机推荐

  1. Parentheses Sequence微软编程笔试

    描述 You are given a sequence S of parentheses. You are asked to insert into S as few parentheses as p ...

  2. Learning OSG programing---osgAnimation(2)

    osg::Node* createBase(const osg::Vec3& center,float radius) { ; ; *radius; *radius; osg::Vec3 v0 ...

  3. GD Library extension not available

    在后台文章上传封面时,遇到了这样一个错误 GD Library extension not available with this PHP installation Ubuntu Nginx 自己在本 ...

  4. Object.entries

    const reduce = Function.bind.call(Function.call, Array.prototype.reduce); const isEnumerable = Funct ...

  5. oracle存储过程调试-plsql

    1.搜索找到存储过程的包,并打开 选中右击--view spec&body 2.找到要测试的存储过程,设置断点,进行测试

  6. yum安装时出现No more mirrors to try.

    可能原因:可能是不正常删除造成的 解决方法: yum clean allyum makecacheyum -y update 然后重新安装

  7. 部署Lighttpd到252板子

    1.先到lighttpd官网下载对应版本的软件包: 如: lighttpd-1.4.30.tar.gz 2. 将压缩包解压到任意目录得到文件夹 lighttpd-1.4.30 3. 执行配置命令:  ...

  8. 20180119-01-RACSignal的基础

    一.获取一个信号的方式 1.单元信号 RACSignal *signal1 = [RACSignal return:@"Some Value"]; RACSignal *signa ...

  9. Beta阶段成果展示——第八组

    Beta阶段成果展示 游戏公网IP:http://119.29.32.204/krad.html(欢迎大家测试!) Beta阶段体现在成果上的工作主要为界面美化,玩家引导,按键封闭等等. 本文将以截图 ...

  10. KMP,Trie,AC自动机题目集

    字符串算法并不多,KMP,trie,AC自动机就是其中几个最经典的.字符串的题目灵活多变也有许多套路,需要多做题才能体会.这里收集了许多前辈的题目做个集合,方便自己回忆. KMP题目:https:// ...