https://www.luogu.com.cn/problem/P1116
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
long long qmi(int m, int k)
{
int res = 1, t = m;
while (k)
{
if (k&1) res = res * t;
t = t * t;
k >>= 1;
}
return res;
}
int read(){
int x = 0,f = 1;
char c = getchar();
while (c<'0'||c>'9') {
if (c=='-') {
f = -1;
}
c = getchar();
}
while (c>='0'&&c<='9') {
x = x*10+c-'0';
c = getchar();
}
return x*f;
}
#define fi(a,b) for(int i = a; i <= b; i++)
#define fj(a,b) for(int j = a; j >= b; j--)
int rail[1005];
int main(){
int cnt = 0;
int n = read();
fi(1,n) rail[i] = read();
fi(1, n)fj(n - 1, i) if(rail[j+1]<rail[j]){ swap(rail[j+1],rail[j]); cnt++; }
cout<<cnt<<endl;
return 0;
}
/*
4
4 3 2 1
============
6
*/
网友评论