2023牛客多校-H-Matches(贪心+思维)

传送门

#include 

using namespace std;

#define endl "\n"
#define debug cout<<"debug"< PII;
const double eps = 1e-8;
const double PI = 3.14159265358979323;
const int N = 110, M = 2*N, mod = 998244353;
const int INF = 0x3f3f3f3f;

struct Node{
    ll a, b; int st = 0;
};

void solve()
{
    int n; cin>>n;
    ll l[2] = {INF, INF};
    vector p(n);
    for(int i = 0; i>p[i].a;
    ll sum = 0;
    for(int i = 0; i>p[i].b;
        sum += abs(p[i].a - p[i].b);
        if(p[i].a == p[i].b) continue;
        if(p[i].a>p[i].b) p[i].st = 1, swap(p[i].a, p[i].b);
    }
    // 将所有ai bi化为abj 有反序的最小左端l = ai, 此时交换ai aj ,即为最大的减小区间差 然后记录当前状态的最小左端
    // 贪心进行更新, 找到最大可更新区间
    for(int i = n-1; i>=0; i--)
    {
        int f = p[i].st;
        if(l[f^1]>T;
    while(T -- )
    {
        solve();
    }
    return 0;
}

你可能感兴趣的:(23牛客多校,c++,算法)