当前位置:网站首页>ZOJ - 4104 sequence in the pocket
ZOJ - 4104 sequence in the pocket
2022-06-24 16:00:00 【51CTO】
Original link : https://zoj.pintia.cn/problem-sets/91827364500/problems/91827370499

The test sample :
Sample Input
2
4
1 3 2 4
5
2 3 3 5 5
Sample Output
2
0
Sample explanation :
For the first sample test case , Move the third element to the front ( So the sequence becomes {2,1,3,4}), Then move the second element to the front ( So the sequence becomes {1, 2, 3,4}). Now? , The sequence is not decreasing .
For the second sample test case , Since the sequence has been sorted , Therefore, no operation is required .
The question : Here's a sequence of integers , You can move an element in the sequence to the front of the sequence any number of times , Ask how many times you have to go through at least to make this sequence not decreasing .
Their thinking : The topic is really simple , Our goal is to make the sequence not decreasing , So what if you encounter a decreasing ? Should we arrange it in order so that the sequence does not decrease , But not everyone has to operate ? That must not be , Our final sequence state is our ordered sequence , Then we use this ordered sequence to compare with the original sequence from back to front ( The comparison from back to front is because our operation is to put in front of the sequence ), Just judge which ones are not operated , So the other thing is to make the sequence non decreasing by moving to the front of the sequence .OK, Let's look at the code .
AC Code :
/*
*
*/
//POJ I won't support it
//i Is a cyclic variable ,a For the initial value ,n Is the limit value , Increasing
//i Is a cyclic variable , a For the initial value ,n Is the limit value , Decline .
using
namespace
std;
const
int
inf
=
0x3f3f3f3f;
// infinity
const
int
maxn
=
1e5;
// Maximum .
typedef
long
long
ll;
typedef
long
double
ld;
typedef
pair
<
ll,
ll
>
pll;
typedef
pair
<
int,
int
>
pii;
//******************************* Split line , The above is a custom code template ***************************************//
int
t,
n,
a[
maxn],
b[
maxn];
int
main(){
//freopen("in.txt", "r", stdin);// When submitting, you should comment out
IOS;
while(
cin
>>
t){
while(
t
--){
cin
>>
n;
rep(
i,
0,
n
-
1){
cin
>>
a[
i];
b[
i]
=
a[
i];
}
sort(
b,
b
+
n);
// Sort
int
pos
=
n
-
1,
sum
=
0;
//sum Count the number of times we have to move to the front
per(
i,
n
-
1,
0){
if(
a[
i]
==
b[
pos])
pos
--;
// There is no need to move forward
else
sum
++;
// Operation forward
}
cout
<<
sum
<<
endl;
}
}
return
0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
边栏推荐
- MongoDB入門實戰教程:學習總結目錄
- Global and Chinese market of computer protective film 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of training dance clothes 2022-2028: Research Report on technology, participants, trends, market size and share
- ZOJ——4104 Sequence in the Pocket(思维问题)
- Rush for IPO, Hello, I'm in a hurry
- Flink Kubernetes Application部署
- Golang+redis reentrant lock
- Leetcode 139. Mot break word Split (medium)
- Install the imagemagick7.1 library and the imageick extension for PHP
- [download attached] installation and simple use of Chinese version of awvs
猜你喜欢

MySQL binlog

Apple is no match for the longest selling mobile phone made in China, and has finally brought back the face of the domestic mobile phone

一文详解JackSon配置信息
![[interview high frequency questions] sequential DP questions with difficulty of 3/5 and direct construction](/img/32/720ffa63a90cd5d37460face3fde38.png)
[interview high frequency questions] sequential DP questions with difficulty of 3/5 and direct construction

使用阿里云RDS for SQL Server性能洞察优化数据库负载-初识性能洞察

Using oasis to develop a hop by hop (I) -- Scene Building

打破内存墙的新利器成行业“热搜”!持久内存让打工人也能玩转海量数据+高维模型

One article explains Jackson configuration information in detail

如何扩展aws主机上的磁盘空间

Still worried about missing measurements? Let's use Jacobo to calculate the code coverage
随机推荐
CAP:多重注意力机制,有趣的细粒度分类方案 | AAAI 2021
Mongodb Getting started Practical Tutoriel: Learning Summary Table des matières
Mysql之Binlog
Intelij 中的 Database Tools可以连接但是无法显示SCHEMA, TABLES
60 divine vs Code plug-ins!!
How to easily realize online karaoke room and sing "mountain sea" with Wang Xinling
个人常用的高效工具
D. Solve The Maze(思维+bfs)Codeforces Round #648 (Div. 2)
Step by step import RHEL image to Tencent cloud
运营商5G用户渗透远远比4G慢,5G的普及还得看中国广电
Solution of intelligent all in one machine in expressway service area
Nature publishes significant progress in quantum computing: the first quantum integrated circuit implementation in history
Poor remote code execution in Alien Swarm
Using oasis to develop a hop by hop (I) -- Scene Building
nifi从入门到实战(保姆级教程)——环境篇
Leetcode 139. Mot break word Split (medium)
不忘初心
Global and Chinese markets of stainless steel barbecue ovens 2022-2028: Research Report on technology, participants, trends, market size and share
Junit5中的参数化测试(Parameterized Tests)指南
安装ImageMagick7.1库以及php的Imagick扩展