当前位置:网站首页>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.
边栏推荐
- 如何轻松实现在线K歌房,与王心凌合唱《山海》
- I just came back from the Ali software test. I worked for Alibaba P7 in 3+1, with an annual salary of 28*15
- Remain true to our original aspiration
- 实现领域驱动设计 - 使用ABP框架 - 领域逻辑 & 应用逻辑
- #夏日挑战赛# HarmonyOS - 实现带日期效果的待办事项
- 安装ImageMagick7.1库以及php的Imagick扩展
- 2021-04-27: if the adjacent position of a character does not have the same character
- C. Three displays(动态规划)Codeforces Round #485 (Div. 2)
- 2021-04-29: given an array arr, it represents a row of balloons with scores. One for each blow
- The equipment is connected to the easycvr platform through the national standard gb28181. How to solve the problem of disconnection?
猜你喜欢

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

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

Vim编辑器的最常用的用法

Logging is not as simple as you think

How to easily realize online karaoke room and sing "mountain sea" with Wang Xinling
![[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

Mongodb Getting started Practical Tutoriel: Learning Summary Table des matières

I just came back from the Ali software test. I worked for Alibaba P7 in 3+1, with an annual salary of 28*15

微信公众号调试与Natapp环境搭建

How to expand disk space on AWS host
随机推荐
存在安全隐患 部分冒险家混动版将召回
2021-05-01: given an ordered array arr, it represents the points located on the X axis. Given a positive number k
HMM to CRF understanding and learning notes
ThinkPHP 漏洞利用工具
Firefox browser uses plug-ins to set up proxy
How to select an open source license
2021-04-28: force buckle 546, remove the box. Give some boxes of different colors
Summary of common tools and usage
打破内存墙的新利器成行业“热搜”!持久内存让打工人也能玩转海量数据+高维模型
[interview high frequency questions] sequential DP questions with difficulty of 3/5 and direct construction
运营商5G用户渗透远远比4G慢,5G的普及还得看中国广电
2021-05-02: given the path of a file directory, write a function
Cap: multiple attention mechanism, interesting fine-grained classification scheme | AAAI 2021
Database tools in intelij can connect but cannot display schema, tables
[C language questions -- leetcode 12 questions] take you off and fly into the garbage
sql 多表更新数据非常慢
Install the imagemagick7.1 library and the imageick extension for PHP
60 个神级 VS Code 插件!!
基于STM32的MD5校验
Linux record -4.22 MySQL 5.37 installation (supplementary)