其他分享
首页 > 其他分享> > CF.1530 Pursuit

CF.1530 Pursuit

作者:互联网

Pursuit

链接:https://codeforces.com/contest/1530/problem/C
构造法的运用

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 100010;
int ga[N], gb[N];
int pre_a[N], pre_b[N];

int main () {
    int cases; cin >> cases;
    while (cases --) {
        int n; cin >> n;
        for (int i = 1; i <= n; i++) cin >> ga[i];
        for (int i = 1; i <= n; i++) cin >> gb[i];
        int num = n - n / 4; // 目前计分的场次
        sort(ga+1, ga+n+1, greater<int>());
        sort(gb+1, gb+n+1, greater<int>());

        int sca = 0, scb = 0;
        for (int i = 1; i <= num; i++) sca += ga[i], scb += gb[i];

        if (sca >= scb) { cout << 0 << endl; continue; }
        int lev = n, pot_a = num, pot_b = num + 1;
        while (++ lev) { // 枚举之后的每一次比赛
            // 如果是4倍数,这一场不增加计分场次,把自己分数最差的换成100
            if (lev % 4 == 0) {
                sca += 100 - ga[pot_a--];
            }
            // 增加一次计分场次,自己加100,对方如果还有分,加上,没有,加0
            else {
                sca += 100;
                if (pot_b <= n) scb += gb[pot_b++];
            }
            if (sca >= scb) break;
        }
        cout << lev - n << endl;
    }
}

标签:include,int,scb,Pursuit,ga,cases,CF.1530,gb
来源: https://www.cnblogs.com/Eval-little/p/15039127.html