当前位置:网站首页>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 in the way of winning 100% of the new bonds
- Solution of separating matlab main window and editor window into two interfaces
- AI clothing generation helps you complete the last step of clothing design
- ACM. Hj70 matrix multiplication calculation amount estimation ●●
- ASP.NET会议室预约小程序源码 预约小程序源码
- 使用ShaderGraph制作边缘融合粒子Shader的启示
- 2022年海外电商运营三大关键讲解
- Introduction to CUDA Programming minimalist tutorial
- Error log format and precautions
- Charles packet capturing tool
猜你喜欢

数组-一口气冲完快慢指针

Array - fast and slow pointer in one breath

Overview of AOSP ~ WiFi architecture

Introduction to CUDA Programming minimalist tutorial

TCC mode explanation and code implementation of Seata's four modes

Transformers Roberta如何添加tokens

Software testing weekly (issue 77): giving up once will breed the habit of giving up, and the problems that could have been solved will become insoluble.

Expressing the transformation of two coordinate systems with vectors

Once beego failed to find bee after passing the go get command Exe's pit

What if Alipay is controlled by risk for 7 days? Payment solution
随机推荐
We media do not know how to realize it? Sharing of 7 major realization methods
2022年海外电商运营三大关键讲解
36岁前亚马逊变性黑客,窃取超1亿人数据被判20年监禁!
DSPACE set zebra crossings and road arrows
Wechat applet obtains the parameters carried after scanning the QR code
VSCode中如何实现点击DOM自动定位到相应代码行
Difference between left join on and join on
20 years ICPC Macau station L - random permutation
doak-cms 文章管理系统 推荐
网上开户股票安全吗?怎么开户呢?
DSPACE的性能渲染问题
Is it safe to open an account in the way of winning 100% of the new bonds
Detailed explanation of cache (for the postgraduate entrance examination of XD)
给你讲懂 MVCC 续篇
Skywalking implements cross thread trace delivery
How transformers Roberta adds tokens
There is the word "Internet" in the concept of industrial Internet, but it is an existence that is not related to the Internet
Copilot免费时代结束!学生党和热门开源项目维护者可白嫖
Call system function security scheme
Administrator如何禁止另一个人踢掉自己?