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;
}
Codeforces Round #588 (Div. 2) D. Marcin and Training Camp(思维)的更多相关文章
- Codeforces Round #588 (Div. 2)-E. Kamil and Making a Stream-求树上同一直径上两两节点之间gcd的和
Codeforces Round #588 (Div. 2)-E. Kamil and Making a Stream-求树上同一直径上两两节点之间gcd的和 [Problem Description ...
- Codeforces Round #588 (Div. 2)
传送门 A. Dawid and Bags of Candies 乱搞. Code #include <bits/stdc++.h> #define MP make_pair #defin ...
- Codeforces Round #588 (Div. 1) 简要题解
1. 1229A Marcin and Training Camp 大意: 给定$n$个对$(a_i,b_i)$, 要求选出一个集合, 使得不存在一个元素好于集合中其他所有元素. 若$a_i$的二进制 ...
- Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)
Problem Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...
- Codeforces Round #588 (Div. 2) E. Kamil and Making a Stream(DFS)
链接: https://codeforces.com/contest/1230/problem/E 题意: Kamil likes streaming the competitive programm ...
- 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 ...
- Codeforces Round #588 (Div. 2) B. Ania and Minimizing(构造)
链接: https://codeforces.com/contest/1230/problem/B 题意: Ania has a large integer S. Its decimal repres ...
- Codeforces Round #588 (Div. 2) A. Dawid and Bags of Candies
链接: https://codeforces.com/contest/1230/problem/A 题意: Dawid has four bags of candies. The i-th of th ...
- Codeforces Round #588 (Div. 1)
Contest Page 因为一些特殊的原因所以更得不是很及时-- A sol 不难发现当某个人diss其他所有人的时候就一定要被删掉. 维护一下每个人会diss多少个人,当diss的人数等于剩余人数 ...
随机推荐
- CREATE TABLE——数据定义语言 (Data Definition Language, DDL)
Sql语句分为三大类: 数据定义语言,负责创建,修改,删除表,索引和视图等对象: 数据操作语言,负责数据库中数据的插入,查询,删除等操作: 数据控制语言,用来授予和撤销用户权限. 数据定义语言 (Da ...
- 数据分析—win7+ipython+notebook安装
先安装python 3.x 然后 cmd 执行 pip3 ipython 然后 cmd 执行 pip3 install jupyter notebook 然后 cmd 执行 jupyter noteb ...
- Devexpress xaf BO中字段为RuleRequiredField必输字段时,文本标签默认添加*标记
BO中字段为RuleRequiredField必输字段时,文本标签默认添加*标记.需要在模型编辑器中设置,如图. 官网地址:https://docs.devexpress.com/eXpressApp ...
- SQL Server循环插入
一个SQL循环插入的代码,运行正常: BEGIN DECLARE @idx AS INT; DECLARE @NodeName nvarchar(255); DECLARE @OtherName nv ...
- linux 安装apache
APR and APR-Util包 下载地址:http://apr.apache.org PCRE 下载地址:http://www.pcre.org Apache Server2.4 下载地址:htt ...
- VMware与主机联网设置
1.编辑-虚拟机网络编辑器 2.虚拟机设置 3. 4.主机ping虚拟机
- hdu 3549 初试最大流问题
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tota ...
- Pattern Recognition and Machine Learning-01-Preface
Preface Pattern recognition has its origins in engineering, whereas machine learning grew out of com ...
- kubernetes 集群内部访问外部的数据库endpoint
k8s访问集群外独立的服务最好的方式是采用Endpoint方式,以mysql服务为例: 创建mysql-service.yaml apiVersion: v1 kind: Service metada ...
- js获取图片内容上传
<script> $('#pic').change(function(){ var size=document.getElementById('pic').files[0].size va ...