当前位置:网站首页>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.
边栏推荐
- 同花顺证券开户是安全的吗?
- Modifying universal render data at runtime
- Array - fast and slow pointer in one breath
- AOSP ~ 默认属性值
- 什么是SSL证书,拥有一个SSL证书有什么好处?
- 好用的字典-defaultdict
- PE file infrastructure sorting
- ACM. Hj70 matrix multiplication calculation amount estimation ●●
- Getting started with unityshader Essentials - PBS physics based rendering
- 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.
猜你喜欢

nacos实践记录

Performance rendering of dSPACE

MySQL modifies and deletes tables in batches according to the table prefix

Getting started with unityshader - Surface Shader

Lihongyi, machine learning 6 Convolutional neural network

Please check the list of commonly used software testing tools.

Seata四大模式之TCC模式详解及代码实现

20年ICPC澳门站L - Random Permutation

Array - fast and slow pointer in one breath

automated testing
随机推荐
Administrator如何禁止另一个人踢掉自己?
CMakeLists中的add_definitions()函数
The era of copilot free is over! Student party and defenders of popular open source projects can prostitute for nothing
Difference between left join on and join on
打新债100%中签的方法 开户是安全的吗
Advanced mathematics | proficient in mean value theorem problem solving routines summary
PE file infrastructure sorting
VSCode中如何实现点击DOM自动定位到相应代码行
MySql安装教程
DateTimeFormat放到@RequestBody下是无效的
Tell you about mvcc sequel
浏览器下载的文件属性里都有保护,如何去掉
打新债是不是骗局 开户是安全的吗
AI clothing generation helps you complete the last step of clothing design
[proteus simulation] Arduino uno+ relay controls lighting equipment
小米路由R4A千兆版安装breed+OpenWRT教程(全脚本无需硬改)
在华泰证券上面开股票账户好不好,安不安全?
Is it safe to open an account with flush securities?
How to choose a securities company when opening an account with a compass? Which is safer
Nacos practice record