当前位置:网站首页>Sorting of poor cattle (winter vacation daily question 40)
Sorting of poor cattle (winter vacation daily question 40)
2022-06-25 03:33:00 【51CTO】
Farmer John Trying to put his A cow , For convenience, the number is
, Put them in order before they go to the pasture for breakfast .
At present , These cows feed on Line up in the order of ,Farmer John Standing on the cow
front .
He wants to rearrange these cows , Make their order , cow
stay Farmer John side .
The cows are a little sleepy today , So at any time, only direct face Farmer John Your cow will listen Farmer John Instructions .
He can move back along the line every time Step ,
It can be a range
Any number in .
She passed by A cow will move forward , Make room for her to insert behind these cows in the team .
for example , hypothesis , The cows started in this order :
FJ: 4, 3, 2, 1
The only thing to notice FJ The cow instructed is the cow .
When he ordered her to move behind the line After step , The order of the team will become :
FJ: 3, 2, 4, 1
Now the only thing to notice FJ The cow instructed is the cow , So the second time he can give the cow
Give orders , Do this until the cows are in order .
Farmer John Eager to finish sorting , So he can go back to his farmhouse and enjoy his own breakfast .
Please help him find out the minimum number of operations required to put the cows in order .
Input format
The first line of input contains .
The second line contains Space separated integers ,
, Indicates the starting order of cows .
Output format
Output an integer , by Farmer John Using the best strategy can make this The number of operations required for a good order of head milk steak .
Data range
sample input :
4
1 2 4 3
sample output :
3
using namespace std;
const int N = 110;
int n;
int a[ N];
int main(){
scanf( "%d", & n);
for( int i = 1; i <= n; i ++) scanf( "%d", & a[ i]);
a[ 0] = n + 1;
for( int i = n; i >= 1; i --)
if( a[ i] < a[ i - 1]){
printf( "%d", i - 1);
break;
}
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.
边栏推荐
- Is it safe to open an account online? Online and other answers
- When people look at the industrial Internet from the Internet like thinking and perspective, they have actually fallen into a dead end
- Getting started with unityshader - Surface Shader
- DSPACE设置斑马线和道路箭头
- 20年ICPC澳门站L - Random Permutation
- How does the administrator prohibit another person from kicking himself?
- Li Kou daily question - day 26 -506 Relative rank
- How can novices of cross-border e-commerce prevent store association? What tool is good?
- DateTimeFormat放到@RequestBody下是无效的
- DSPACE set zebra crossings and road arrows
猜你喜欢
How to raise key issues in the big talk club?
Tutoriel d'installation MySQL
nacos实践记录
MySQL installation tutorial
Detailed explanation of cache (for the postgraduate entrance examination of XD)
Insurance app aging service evaluation analysis 2022 issue 06
Once beego failed to find bee after passing the go get command Exe's pit
Performance rendering of dSPACE
MATLAB主窗口与编辑器窗口分开为两个界面的解决办法
好用的字典-defaultdict
随机推荐
36岁前亚马逊变性黑客,窃取超1亿人数据被判20年监禁!
Enlightenment of using shadergraph to make edge fusion particle shader
nacos实践记录
AOSP ~ WIFI架构总览
股票开户,在手机上开户安全吗?
Introduction to CUDA Programming minimalist tutorial
SkyWalking 实现跨线程 Trace 传递
How can novices of cross-border e-commerce prevent store association? What tool is good?
Tutoriel d'installation MySQL
Is flush a regular platform? Is it safe for flush to open an account
Rebeco: using machine learning to predict stock crash risk
How transformers Roberta adds tokens
mysql学习笔记--单张表上的增删改查
Unity archive system - file in JSON format
ACM. HJ70 矩阵乘法计算量估算 ●●
DateTimeFormat放到@RequestBody下是无效的
用指南针开户如何选择证券公司?哪一个是更安全的
Is it safe to open an account on your mobile phone?
电脑端微信用户图片DAT格式解码为图片(TK版)
AI自己写代码让智能体进化!OpenAI的大模型有“人类思想”那味了