Codeforces Round #588 (Div. 2)

Posted gredcomet

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #588 (Div. 2)相关的知识,希望对你有一定的参考价值。

题目链接

C:
本题可以直接暴力求解,类比八皇后问题,使每个点分别对应一个值,分别判断有几条边能够满足即可

#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

bool vis[8][8];
int col[8];

void run_case() {
    int n, m;
    cin >> n >> m;
    vector<pii> a(m);
    for(int i = 0; i < m; ++i)
        cin >> a[i].first >> a[i].second;
    int ans = 0;
    function<void(int)> dfs = [&](int x) {
        if(x > n) {
            int cnt = 0;
            ms(vis, 0);
            for(int i = 0; i < m; ++i) {
                if(vis[col[a[i].first]][col[a[i].second]]) continue;
                vis[col[a[i].first]][col[a[i].second]] = vis[col[a[i].second]][col[a[i].first]] = true;
                cnt++;
            }
            ans = max(ans, cnt);
            return;
        }
        for(int i = 1; i <= 6; ++i) {
            col[x] = i;
            dfs(x+1);
        }
    };
    dfs(1);
    cout << ans;
}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}

D:
读懂题意后也不难,至少有2个人是calm的,则集合中至少有2个人的knowledge是相等的,设为(x),然后再遍历,设(y)为当前的值,若(x&y==y),则说明(x geq y)(y)中拥有的knowledge(x)都有

#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


void run_case() {
    int n; cin >> n;
    vector<LL> a(n), b(n), valid;
    map<LL, int> mp;
    for(auto &x: a) {
        cin >> x;
        mp[x]++;
    }
    for(auto &x: b) cin >> x;
    for(auto i: mp)
        if(i.second > 1)
            valid.push_back(i.first);
    LL ans = 0;
    for(int i = 0; i < n; ++i) {
        for(auto j: valid) {
            if((a[i]&j)==a[i]) {
                ans += b[i];
                break;
            }
        }
    }
    cout << ans;
}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}


以上是关于Codeforces Round #588 (Div. 2)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #588 (Div. 2)

Codeforces Round #588 (Div. 2) C. Anadi and Domino(思维)

Codeforces Round #588 (Div. 1)

B. Ania and Minimizing (Codeforces Round #588 (Div. 2) )

Codeforces Round #588 (Div. 2) D. Marcin and Training Camp(思维)

D. Marcin and Training Camp ( Codeforces Round #588 (Div. 2) )