【2019浙江省赛 - E】Sequence in the Pocket(思维)

题干:

DreamGrid has just found an integer sequence  in his right pocket. As DreamGrid is bored, he decides to play with the sequence. He can perform the following operation any number of times (including zero time): select an element and move it to the beginning of the sequence.

What's the minimum number of operations needed to make the sequence non-decreasing?

Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains an integer  (), indicating the length of the sequence.

The second line contains  integers  (), indicating the given sequence.

It's guaranteed that the sum of  of all test cases will not exceed .

Output

For each test case output one line containing one integer, indicating the answer.

Sample Input

2
4
1 3 2 4
5
2 3 3 5 5

Sample Output

2
0

Hint

For the first sample test case, move the 3rd element to the front (so the sequence become {2, 1, 3, 4}), then move the 2nd element to the front (so the sequence become {1, 2, 3, 4}). Now the sequence is non-decreasing.

For the second sample test case, as the sequence is already sorted, no operation is needed.

解题报告:

排好序就确定了他最终的状态,找到每个值最终出现的位置就行了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int a[MAX],b[MAX];
int n;
int main()
{int t;cin>>t;while(t--) {scanf("%d",&n);for(int i = 1; i<=n; i++) {scanf("%d",a+i);b[i] = a[i];}sort(b+1,b+n+1);int all = 0;for(int i = n; i>=1; i--) {if(a[i] == b[i+all]) continue;else all++;}printf("%d\n",all);}return 0 ;}
/*
100
5
1 2 2 5 1
1 1 2 2 5
*/

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440394.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

android和ios系统的内存,WP和Saipan系统的流畅程度相当于ios,占用的内存很少,但是为什么要用Android取代它...

当涉及到WP和Symbian系统时&#xff0c;许可能没有听说过它&#xff0c;但是对于大多数关注智能手机市场增长的消费者来说&#xff0c;它已经为人们所熟悉&#xff0c;并且许已经使用了它. 当时在功能性机器上使用了Saipan系统&#xff0c;但是您会发现该系统的流畅性与当时的i…

【CodeForces - 1042C】Array Product(思维,有坑细节)

题干&#xff1a; You are given an array aa consisting of nn integers. You can perform the following operations with it: Choose some positions ii and jj (1≤i,j≤n,i≠j1≤i,j≤n,i≠j), write the value of ai⋅ajai⋅aj into the jj-th cell and remove the num…

红米pro android o刷机,红米Pro如何刷机?你可以通过这两种方法获取root权限!

小米官网最近发布了关于红米pro的消息&#xff0c;相信很多米粉们已经上手了&#xff0c;那么新到手的机子怎么刷机呢&#xff1f;下面小编为大家带来一个完整的红米Pro官方卡刷机教程&#xff0c;希望可以帮助到大家。红米Pro卡刷升级教程&#xff1a;准备工作1.进入红米Pro刷…

【2019浙江省赛 - K 】Strings in the Pocket(马拉车,思维)

题干&#xff1a; BaoBao has just found two strings and in his left pocket, where indicates the -th character in string , and indicates the -th character in string . As BaoBao is bored, he decides to select a substring of and reverse it. Formally spe…

android+微信一键关注,一键关注微信公众平台JS代码有哪些?

一键关注微信公众平台JS代码有哪些&#xff1f;在网页设置一个按钮或者链接可以让用户一键关注微信公众平台&#xff0c;那么这种一键关注微信公众平台的功能如何实现呢&#xff1f;下面小编分享给大家一键关注微信公众平台的JS代码。在微信上&#xff0c;通过微信公众平台推送…

【2019浙江省赛 - A】Vertices in the Pocket(权值线段树下二分,图,思维)

题干&#xff1a; DreamGrid has just found an undirected simple graph with vertices and no edges (thats to say, its a graph with isolated vertices) in his right pocket, where the vertices are numbered from 1 to . Now he would like to perform operations …

html写原生曲线图,HTML5 平滑的正弦波曲线图

JavaScript语言&#xff1a;JaveScriptBabelCoffeeScript确定var waves new SineWaves({el: document.getElementById(waves),speed: 4,width: function() {return $(window).width();},height: function() {return $(window).height();},ease: SineInOut,wavesWidth: 80%,wav…

【CodeForces - 1150C】Prefix Sum Primes(思维)

题干&#xff1a; Were giving away nice huge bags containing number tiles! A bag we want to present to you contains nn tiles. Each of them has a single number written on it — either 11or 22. However, there is one condition you must fulfill in order to re…

asp.net 写入html代码,asp.net读取模版并写入文本文件

本文要介绍的是ASP.NET怎样读写文本文件&#xff0c;但更重要的是实现的过程。使用的工具是Visual Studio 2015 &#xff0c;.NET版本是4.6.1 。一共建立的2个项目&#xff0c;HoverTreePanel和HoverTreeWeb&#xff0c;都是ASP.NET项目。文章末尾附源码下载。项目结果如下图&a…

【CodeForces - 1150A】Stock Arbitraging (贪心,水题)

题干&#xff1a; Welcome to Codeforces Stock Exchange! Were pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope youll still be able to make profit from the market! In the morning, there are nn opportunities to buy share…

html以图像中心定位,在HTML图像上水平和垂直居中文本(绝对定位)

Michael Roach0htmlcssflexbox鉴于以下设计元素,我试图在html中包含图像,以便可以使用css过渡(悬停效果)操纵不透明度.这里的主要缺点是我使用手动垂直居中(绝对/顶部:4​​0%),这在缩小浏览器时变得明显.在使用绝对定位时,是否可以使用flexbox或table进行垂直居中&#xff1f;…

*【CodeForces - 1150D】Three Religions(dp,预处理,思维)

题干&#xff1a; During the archaeological research in the Middle East you found the traces of three ancient religions: First religion, Second religion and Third religion. You compiled the information on the evolution of each of these beliefs, and you now…

基于android公交车线路查询论文文献,本科毕业论文---基于android的手机公交线路查询系统.doc...

毕 业 设 计( 论 文 )题目手机公交线路查询系统作者学院专业学号指导教师摘 要关键词&#xff1b;AbstractWith the level of people’s life improving,going out by bus become a necessary part of daily life.And the traffic line to destination should be known everyti…

【POJ - 3159】Candies (差分约束,卡SPFA)

题干&#xff1a; 在幼儿园的时候&#xff0c;Flymouse是班上的班长。有时班主任会给班上的孩子们带来一大袋糖果&#xff0c;让他们分发。所有的孩子都非常喜欢糖果&#xff0c;经常比较他们和别人买的糖果的数量。一个孩子A可以有这样的想法&#xff0c;尽管可能是另一个孩子…

计算机英语第六单元,计算机专业英语第六版第十单元课后汉译英,We do use other forms....这个do...

同样的 &#xff0c;多线程也存在许多缺点 &#xff0c;在考虑多线程时需要进行充分的考虑。多线程的主要缺点包括&#xff1a;Similarly, multi thread also has many shortcomings, in the consideration of the need for the full consideration of multiple threads. The m…

1.Hello,Python

本文为Kaggle Learn的Python课程的中文翻译&#xff0c;原文链接为&#xff1a;https://www.kaggle.com/colinmorris/hello-python 欢迎来到Kaggle Learn的Python课程。本课程将介绍在开始使用Python进行数据科学之前需要的基本Python技能。这些课程针对那些具有一些编程经验的…

【POJ - 1273】Drainage Ditches(网络流,最大流,模板)

题干&#xff1a; 现在有m个池塘(从1到m开始编号,1为源点,m为汇点),及n条水渠,给出这n条水渠所连接的点和所能流过的最大流量&#xff0c;求从源点到汇点能流过的最大流量。 Input 输入包括几种情况。 对于每种情况&#xff0c;第一行包含两个空格分隔的整数&#xff0c;N&a…

计算机网络阶段,计算机网络的发展大致可分为四个阶段,目前人类进入了()。 - 问答库...

问题&#xff1a;[单选] 计算机网络的发展大致可分为四个阶段&#xff0c;目前人类进入了()。A . 计算机网络阶段B . 信息高速公路阶段C . 计算机网络互联阶段D . 远程终端联机阶段教育心理学是研究教育情境中学生学习的基本心理规律的科学。王林平时成绩一般&#xff0c;但总想…

2.Functions and Getting Help

Functions and Getting Help 在本课中&#xff0c;我们将讨论函数&#xff1a;调用它们&#xff0c;定义它们&#xff0c;并使用Python的内置文档查找它们。 在某些语言中&#xff0c;定义函数必须要有特定的参数&#xff0c;每个参数都具有特定类型。 Python函数允许更灵活。…

华人科学家量子计算机,华人科学家在美国研发出性能强大的光子计算机,能够与中国的量子计算机一战高下!...

原标题&#xff1a;华人科学家在美国研发出性能强大的光子计算机&#xff0c;能够与中国的量子计算机一战高下&#xff01;在最近的《自然纳米技术》杂志上&#xff0c;一篇来自美国哥伦比亚大学的论文在业界掀起了轩然大波&#xff0c;一位名叫虞南方的物理学助理教授成功率领…