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

链接:

https://codeforces.com/contest/1230/problem/D

题意:

Marcin is a coach in his university. There are n students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.

Let‘s focus on the students. They are indexed with integers from 1 to n. Each of them can be described with two integers ai and bi; bi is equal to the skill level of the i-th student (the higher, the better). Also, there are 60 known algorithms, which are numbered with integers from 0 to 59. If the i-th student knows the j-th algorithm, then the j-th bit (2j) is set in the binary representation of ai. Otherwise, this bit is not set.

Student x thinks that he is better than student y if and only if x knows some algorithm which y doesn‘t know. Note that two students can think that they are better than each other. A group of students can work together calmly if no student in this group thinks that he is better than everyone else in this group.

Marcin wants to send a group of at least two students which will work together calmly and will have the maximum possible sum of the skill levels. What is this sum?

思路:

由题意可得, 组合内必须有两个相同的, 考虑所有拥有两个或两个以上相同a的集合.
这些集合可以组成一个大集合.同时其他值只要不存在有这些集合共有的值即可.
判定过程使用位运算可以优化到O(n)(没试过)

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 7e3+10;

struct Node
{
    LL a, b;
}node[MAXN];
map<LL, pair<int, LL> > Mp;
LL Id[MAXN], Val[MAXN];
int n, cnt = 0;

bool Check(LL a, LL b)
{
    while (b)
    {
        if (((a&1) == 0) && ((b&1) == 1))
            return false;
        a >>= 1;
        b >>= 1;
    }
    return true;
}

int main()
{
    cin >> n;
    for (int i = 1;i <= n;i++)
        cin >> node[i].a;
    for (int i = 1;i <= n;i++)
        cin >> node[i].b;
    for (int i = 1;i <= n;i++)
    {
        Mp[node[i].a].first++;
        Mp[node[i].a].second += node[i].b;
    }
    LL maxa = 0, maxb = 0;
    for (auto x:Mp)
    {
        if (x.second.first > 1)
        {
            Id[++cnt] = x.first;
            Val[cnt] = x.second.second;
        }
    }
    if (cnt == 0)
    {
        puts("0");
        return 0;
    }
    LL res = 0;
    for (int i = 1;i <= n;i++)
    {
        for (int j = 1;j <= cnt;j++)
        {
            if (node[i].a == Id[j])
                break;
            if (Check(Id[j], node[i].a))
            {
                res += node[i].b;
                break;
            }
        }
    }
    for (int i = 1;i <= cnt;i++)
        res += Val[i];
    cout << res << endl;

    return 0;
}

原文地址:https://www.cnblogs.com/YDDDD/p/11621900.html

时间: 2024-08-30 02:19:46

Codeforces Round #588 (Div. 2) D. Marcin and Training Camp(思维)的相关文章

Codeforces Round #588 (Div. 2)

Codeforces Round #588 (Div. 2) A. Dawid and Bags of Candies 思路:水题 AC代码 #include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstr

Codeforces Round #480 (Div. 2) C 贪心 D 数字、思维 E 树上倍增

Codeforces Round #480 (Div. 2) C. Posterized 题意: 给出 n 个数,都是区间 [0,255] 内的数,要你把 [0,255] 划分成多个长度 <=k 的不重叠的子区间.每个数必须包含在一个子区间内,且这个数的价值是这个子区间的左端点.要你输出这 n 数的价值,且这 n 个价值字典序要最小. tags: 首先很明显字典序最小,那对于第 i 个数 p[i] 定它的区间时,左端点肯定要尽可能小.所以我们直接枚举区间 [ p[i]-k+1, p[i] ] 定

Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)

Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Description Input Output Sample Input 51 2 1 2 1 Sample Output 1 1 1 2 2 题解:这个题有做慢了,这种题做慢了和没做出来区别不大... 读题的时候脑子里还意识到素数除了2都是奇数,读完之后就脑子里就只剩欧拉筛了,贪心地构造使得前缀和是连续的素数,那

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

Marcin is a coach in his university. There are nn students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other. Let's focus on the students. They are indexed with int

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

链接: https://codeforces.com/contest/1230/problem/C 题意: Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every a and b such that 1≤a≤b≤6, there is exactly one domino with a dots on one half and b dots on th

Codeforces Round #588 (Div. 2) E. Kamil and Making a Stream(DFS)

链接: https://codeforces.com/contest/1230/problem/E 题意: Kamil likes streaming the competitive programming videos. His MeTube channel has recently reached 100 million subscribers. In order to celebrate this, he posted a video with an interesting problem

A. Dawid and Bags of Candies ( Codeforces Round #588 (Div. 2) )

Dawid has four bags of candies. The ii-th of them contains aiai candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount o

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

Ania has a large integer SS. Its decimal representation has length nn and doesn't contain any leading zeroes. Ania is allowed to change at most kk digits of SS. She wants to do it in such a way that SS still won't contain any leading zeroes and it'll

Codeforces Round #588 (Div. 1)

Contest Page 因为一些特殊的原因所以更得不是很及时-- A sol 不难发现当某个人diss其他所有人的时候就一定要被删掉. 维护一下每个人会diss多少个人,当diss的人数等于剩余人数$-1$的时候放队列里,每一次取队头更新其他人diss的人数. code B sol 一个结论:对于序列$a_1,a_2,...,a_n$,其前缀$gcd$数量不超过$log_2a_i$种.证明考虑从前往后计算前缀$gcd$,那么从第$i-1$个$gcd$到第$i$个$gcd$,数值要么不变要么至少