[思维]First Last Sorting

题目:https://www.jisuanke.com/contest/7788/425045
最坏情况是操作n次。最少的操作次数就是用最坏情况减去输入的时候就已经是从小到大排序的个数

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+7;
int num[N];
int main()
{
   
	int n;
	cin>>n;
	int res=0;
	for(int i=1; i<=n; i++) {
   
		int x;
		scanf("%d",&x);
		num[x]=num[x-1]+1;
		res=max(res,num[x]);	
	}
	//最坏情况是n,用n-组成sort序的 
	printf("%d\n",n-res); 
}
全部评论

相关推荐

09-28 22:01
已编辑
广西科技大学 IT技术支持
合适才能收到offe...:找桌面运维?
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务