Codeforces Round #601 (Div. 2) A、B

A传送

B传送

A Changing Volume

AC代码

#include <bits/stdc++.h>
using namespace std;
int t;
int a, b;
 
int main() {
    int t;
    scanf("%d", &t);
    while(t --) {
        
        scanf("%d%d", &a, &b);
        int t = abs(b - a);
        int cnt = t / 5;
        t -= cnt * 5;
        if(t == 3 || t == 4) cout << cnt + 2 << '
';
        else if(t == 2 || t == 1) cout << cnt + 1 << '
';
        else cout << cnt << '
';
    }
    
    return 0;
}

B Fridge Lockers

AC代码

#include <bits/stdc++.h>
using namespace std;

void Solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    if (m < n || n == 2) {
        cout << "-1
";
        return;
    } else {
        cout << 2 * accumulate(a.begin(), a.end(), 0) << '
';
        for (int i = 1; i <= n; i++) {
            if (i == n)
                cout << n << " " << 1 << '
';
            else
                cout << i << " " << i + 1 << '
';
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while (t--) {
        Solve();
    }
    return 0;
}
原文地址:https://www.cnblogs.com/FrankOu/p/14433127.html