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的人数等于剩余人数 ...
随机推荐
- oracle授予权限
CONNECT角色: --是授予最终用户的典型权利,最基本的 CREATE SESSION --建立会话 RESOURCE角色: --是授予开发人员的 CREATE ...
- HDU-6170 Two strings
http://acm.hdu.edu.cn/showproblem.php?pid=6170 . 匹配任意字符,x* 匹配任意长度的 x (x 为任意字符,长度可以为 0 ) 正则表达式 #inclu ...
- 题目13 在O(1)时间删除链表节点
///////////////////////////////////////////////////////////////////////////////////// // 3. 题目13 在O( ...
- EffectiveC++
宁可以编译器替换预处理器 define 不被视为语言的一部分,因此也就有可能在预处理阶段被优化掉,导致相关变量出现错误. #define ASPECT_RATIO 1.63 //可以尝试将其替换为 c ...
- CDN内容分发
什么是CDN内容分发: CDN的全称是Content Delivery Network,即内容分发网络.CDN是构建在网络之上的内容分发网络,依靠部署在各地的边缘服务器,通过中心平台的负载均衡.内容分 ...
- 怎样获取不同环境下的document对象
1. 在一般的网页文档中, 可通过: document 或 window.document 获取; 2. 在iframe框架中, 可通过iframe节点的属性: contentDocument 获取; ...
- CCF - CCSP 2018-01 绝地求生 BFS
BFS从安全地区方向搞一下就好了 1.还是注意每回合清空 2.posx居然开小了,可不能犯这种错误 3.地图用a和节点的dis重名了,建议其他变量禁止用a命名 4.在输入数据之前continue了,这 ...
- [转载]linux的top命令中cpu信息的含义
https://www.cnblogs.com/wjoyxt/p/4918742.html 原文很好,我就不摘录了.
- $.proxy的使用
$.proxy()是jquery的一个方法.是一个改变this指向的方法. 在某些情况下,我们调用Javascript函数时候,this指针并不一定是我们所期望的那个.例如: //正常的this使用 ...
- C语言——指针总结
在创建指针时,我们首先要做的是先初始化它,没有初始化的指针是很危险的,因为指针可以指向一个地址后直接改变它的值,所以为了避免我们的指针在创建后指向一个危险区域(即可能指向系统文件等),我们会先给它一个 ...