Codeforces 1401B Ternary Sequence

题目

1401B

题解

题意

给出两个数组ab,已知其均由012组成,求在题目中所给的方程下所能构造的最大的 ∑ 1 < = i < = n c i \sum_{1<=i<=n} c_i 1<=i<=nci.

题解

尽可能地使a中的2b中的1在相同位置,使b中的2a中的02在相同位置。

AC代码

这里还是可以进行简化的。

#include <bits/stdc++.h>

using namespace std;
//#pragma GCC optimize(2)
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ull unsigned long long
#define ll long long
#define rep(i, x, y) for(int i=x;i<=y;i++)
#define mms(x, n) memset(x, n, sizeof(x))
#define mmc(A, tree) memcpy(A, tree, sizeof(tree))
#define eps (1e-8)
#define PI (acos(-1.0))
#define INF (0x3f3f3f3f)
#define mod (ull)(1e9+7)
typedef pair<int, int> P;

int main() {
    
    
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    int T;
    scanf("%d", &T);
    while (T--) {
    
    
        ll x1, x2, y1, y2, z1, z2;
        scanf("%lld%lld%lld%lld%lld%lld", &x1, &y1, &z1, &x2, &y2, &z2);
        ll sum = 0;
        if (z1 >= y2) {
    
    
            z1 -= y2;
            sum += y2 * 2;
            y2 = 0;
        } else {
    
    
            y2 -= z1;
            sum += z1 * 2;
            z1 = 0;
        }
        if (z2 >= z1) {
    
    
            z2 -= z1;
            z1 = 0;
            if (z2 >= x1) {
    
    
                z2 -= x1;
                x1 = 0;
                sum -= min(y1, z2) * 2;
            }
        }
        printf("%lld\n", sum);
    }
    return 0;
}

后记

WA了很多次QAQ,逻辑不是很严密,继续努力呀!

猜你喜欢

转载自blog.csdn.net/qq_45934120/article/details/108609051
今日推荐