Skip to content
Okami's Blog
Go back

Codeforces Round 664 (Div. 2) 题解

A

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

typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T;
    cin >> T;
    while (T--) {
        int r, g, b, w;
        cin >> r >> g >> b >> w;

        int odd_count = 0;
        odd_count = (r&1) + (g&1) + (b&1) +(w&1);
        if(odd_count == 0 || odd_count == 1) {
            cout<<"Yes"<<endl;
            continue;
        }
        r--;
        g--;
        b--;
        w += 3;
        if(r < 0 || g < 0 || b < 0) {
            cout<<"No"<<endl;
            continue;
        }
        odd_count = (r & 1) + (g & 1) + (b & 1) + (w & 1);
        if (odd_count == 0 || odd_count == 1) {
            cout << "Yes" << endl;
            continue;
        }

        int delta = min(r, (min(g, b)));
        r -= delta;
        g -= delta;
        b -= delta;
        w += 3*delta;
        if (r < 0 || g < 0 || b < 0) {
            cout << "No" << endl;
            continue;
        }
        odd_count = (r & 1) + (g & 1) + (b & 1) + (w & 1);
        if (odd_count == 0 || odd_count == 1) {
            cout << "Yes" << endl;
            continue;
        }
        cout<<"No"<<endl;
    }
}

B

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

typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;

int n, m;
void print(int r, int c) { cout << r + 1 << " " << c + 1 << endl; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int sr, sc;

    cin >> n >> m >> sr >> sc;
    sr--;
    sc--;

    for (int i = 0; i < n; i++) {
        print(sr, sc);
        for (int j = 0; j < m - 1; j++) {
            sc = (sc + 1) % m;
            print(sr, sc);
        }
        sr = (sr + 1) % n;
    }
    return 0;
}

C

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

typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int maxn = 200 + 5;

int n, m;
int a[maxn], b[maxn];

bool check(int ans) {
    //cout << ans << endl;
    for (int i = 0; i < n; ++i) {
        bool found = false;
        for (int j = 0; j < m; ++j) {
            if (((a[i] & b[j]) | ans) == ans) {
                found = true;
                //cout<<"a:"<<i<<" b:"<<j<<endl;
                break;
            }
        }
        if (!found)
            return false;
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < m; ++i)
        cin >> b[i];

    for (int i = 0; i < 512; i++)
        if (check(i)) {
            cout << i << endl;
            return 0;
        }
}

D

WA原因

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

typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int maxn = 100000 + 5;
int d, n, m, lengthOfNotMuzzle;
priority_queue<ll> willMuzzle, notMuzzleQ;
ll notMuzzle[maxn];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> d >> m;
    ll a;
    lengthOfNotMuzzle = 0;
    while(!willMuzzle.empty()) willMuzzle.pop();
    while(!notMuzzleQ.empty()) notMuzzleQ.pop();
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a > m)
            willMuzzle.push(a);
        else
            notMuzzle[lengthOfNotMuzzle++] = a;
    }

    sort(notMuzzle, notMuzzle + lengthOfNotMuzzle);

    ll ans = 0;
    ll groupNumber, remainder;
    groupNumber = n / (d + 1);
    remainder = n % (d + 1);
    if(remainder == 0){
        remainder = d + 1;
        groupNumber--;
    }
    for (int i = 0; i < remainder; i++) {
        if (i == remainder - 1 && !willMuzzle.empty()) {
            ans += willMuzzle.top();
            willMuzzle.pop();
            continue;
        }

        if (lengthOfNotMuzzle > 0) {
            ans += notMuzzle[--lengthOfNotMuzzle];
        }
    }

    while(lengthOfNotMuzzle) {
        ll tmp = 0;
        for(int i = 1; i <= d + 1 && lengthOfNotMuzzle; ++i) {
            tmp += notMuzzle[--lengthOfNotMuzzle];
        }
        notMuzzleQ.push(tmp);
    }

    for (int i = 0; i < groupNumber; i++) {
        ll muzzleIncome = 0;
        if (!willMuzzle.empty())
            muzzleIncome = willMuzzle.top();
        ll notMuzzleIncome = 0;
        if (!notMuzzleQ.empty())
            notMuzzleIncome = notMuzzleQ.top();
        if (muzzleIncome >= notMuzzleIncome) {
            ans += muzzleIncome;
            willMuzzle.pop();
        } else {
            ans += notMuzzleIncome;
            notMuzzleQ.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

E

官方题解

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

typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 200000 + 5;
const int maxk = 9 + 1;
int n, m, k, ans, final_set;
vector<pair<int, int>> edges[maxn];
int hashed_set[maxk][maxk] = {};
int randomized_node_index[maxn] = {};
void insert(int &target_set, int node_index) {
    if (randomized_node_index[node_index] == 0)
        randomized_node_index[node_index] = rand() % MOD + 1;

    target_set = (target_set + randomized_node_index[node_index]) % MOD;
}

int s[maxk] = {};
void cal_ans(int i, int current_t_i) {
    s[i] = (s[i-1] + hashed_set[i][current_t_i]) % MOD;
    if(i == k){
        if(s[i] == final_set)
            ++ans;
        return;
    }
    for(int j = 1; j <= i + 1; ++j)
        cal_ans(i + 1, j);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    srand(time(0));
    cin >> n >> m >> k;

    int u, v, w;
    for (int i = 1; i <= m; ++i) {
        cin >> u >> v >> w;
        edges[u].push_back(pair<int, int>(w, v));
    }

    for (int i = 1; i <= n; ++i)
        sort(edges[i].begin(), edges[i].end());

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= edges[i].size(); ++j)
            insert(hashed_set[edges[i].size()][j], edges[i][j-1].second);

    final_set = 0;
    for(int i = 1; i <= n; ++i)
        insert(final_set, i);
    ans = 0;
    cal_ans(1, 1);

    cout << ans << endl;
    return 0;
    cout<<"fuck";
}

F



Previous Post
《港中深新手村》项目感想
Next Post
关于死亡(其二)