当前位置:网站首页>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.
边栏推荐
猜你喜欢

Copilot免费时代结束!学生党和热门开源项目维护者可白嫖

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

Computer wechat user picture decoded into picture in DAT format (TK version)

vie的刷新机制

DSPACE的性能渲染问题

电脑端微信用户图片DAT格式解码为图片(TK版)

14 bs对象.节点名称.name attrs string 获取节点名称 属性 内容

automated testing

DSPACE set zebra crossings and road arrows

记一次beego通过go get命令后找不到bee.exe的坑
随机推荐
Refresh mechanism of vie
Is it safe to open an account in the way of winning 100% of the new bonds
AOSP ~ default attribute value
保险也能拼购?个人可以凑够人数组团购买医疗保险的4大风险
Is it safe to open an online stock account?
Eggservice builds the basic service of wechat official account
36岁前亚马逊变性黑客,窃取超1亿人数据被判20年监禁!
指南针在上面开户安全吗?靠谱吗?
PE file infrastructure sorting
How to raise key issues in the big talk club?
There is the word "Internet" in the concept of industrial Internet, but it is an existence that is not related to the Internet
Is flush a regular platform? Is it safe for flush to open an account
力扣每日一题-第26天-506.相对名次
@PostConstruct
同花顺证券开户是安全的吗?
MCN institutions are blooming everywhere: bloggers and authors should sign contracts carefully, and the industry is very deep
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.
How transformers Roberta adds tokens
Detailed explanation of cache (for the postgraduate entrance examination of XD)
How does the administrator prohibit another person from kicking himself?