题解:CF2072D For Wizards, the Exam Is Easy, but I Couldn't Handle It
题意
给你
思路
看到数据范围
第一层循环枚举
第二层循环枚举
并在每次循环判断
最终打擂台找出使逆序对最少的
代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll t, n, a[2010], cnt, x, y, ans;
// x 表示 l,y 表示 r
int main()
{
cin >> t;
while (t--) // 多测
{
ans = 0;
x = 1; // 预防如何移动都改变不了逆序对数量的情况,先置为 1
y = 1;
cin >> n;
for (ll i = 1 ; i <= n ; i++) // 输入
{
cin >> a[i];
}
for (ll i = 1 ; i <= n ; i++) // 枚举 l
{
cnt = 0;
// cnt 表示移动 i 所减少的逆序对数量
for (ll j = i + 1 ; j <= n ; j++) // 枚举 r
{
if (a[i] > a[j]) // 逆序对减少
{
cnt++;
}
if (a[i] < a[j]) // 逆序对增加
{
cnt--;
}
if (cnt > ans) // 打擂台找到减少逆序对最多的 l,r
{
ans = cnt;
x = i;
y = j;
}
}
}
cout << x << " " << y << endl;
}
return 0;
}