跳转至

第 1 届本科组(初赛)

T1

#include <iostream>
#include <vector>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<bool> vis(256);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int p = j + 1; p < n; p++) {
                for (int q = p + 1; q < n; q++) {
                    int s = a[i] + a[j] + a[p] + a[q];
                    if (s % 4 == 0) {
                        vis[s / 4] = true;
                    }
                }
            }
        }
    }

    while (k--) {
        int x;
        cin >> x;
        bool ok = true;
        for (int i = 0; i < x; i++) {
            int y;
            cin >> y;
            if (!vis[y]) {
                ok = false;
            }
        }
        cout << (ok ? "Yes" : "No") << "\n";
    }

    return 0;
}

T2

#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

struct node {
    int i, j, val;
    bool operator<(node& t) const {
        if (t.i == this->i) {
            return t.j < this->j;
        }
        return t.i < this->i;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    map<pair<int, int>, vector<node>> a;
    int s = 0;

    for (int i = 0; i < n; i++) {
        int x, y, p;
        cin >> x >> y >> p;

        s += p;
        int gcd = __gcd(x, y);
        gcd = max(gcd, -gcd);
        a[{x / gcd, y / gcd}].push_back({x, y, p});
    }

    int cnt = 0;
    for (auto& [_, v]: a) {
        sort(v.begin(), v.end());
        int t = 0;  // 当前方向需要操作的次数
        for (int i = 0; i < v.size();) {
            t++;
            i++;
            while (i > 0 && v[i].val == 1 && v[i - 1].val == 1) {
                i++;
            }
        }
        cnt += t;
    }

    cout << s << " " << cnt << "\n";

    return 0;
}