原题链接 https://www.luogu.com.cn/problem/P1116
题目描述
每次只能交换相邻两节车厢,求把编号排为升序所需的最少交换次数。
输入 先读车厢数 N,再读 N 个互不相同的编号,编号可能跨行。
输出 一个整数,表示最少交换次数。
输入输出样例
输入
4
4 3 2 1 输出
6题解
n,*g=map(int,open(0).read().split())
res=0
for i in range(n):
for j in range(i+1,n):
if g[i]>g[j]:
res+=1
print(res)