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的人数等于剩余人数 ...
随机推荐
- SpringBoot 使用WebSocket打造在线聊天室
教程: https://www.jianshu.com/p/55cfc9fcb69e https://wallimn.iteye.com/blog/2425666 关于websocket基础普及见:h ...
- 导出远程oracle数据库到本地
1.以管理员身份运行 Net Manager 以管理员身份运行cmd
- 2017"百度之星"程序设计大赛 - 资格赛 1002 度度熊的王国战略
全局最小割 Stoer-Wagner (SW算法)优化 优化吃藕了,感谢放宽时限,感谢平板电视 (pb_ds) #include <iostream> #include <cstdi ...
- Python基础 第四章 字典(1)
通过名称来访问其各个值的数据结构,映射(mapping). 字典,是Python中唯一的内置映射类型,其中的值不按顺序排列,而是存储在键下.(键,可能是数.字符串.元组). 1.1 字典由 键 及其相 ...
- selenium登录实验楼
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.s ...
- Linux 多命令语句与重定向
多命令语句 Linux中我们在shell输入命令一般是一条一条执行,但是我们同样可以用一行语句写出多命令,下面就举出几个常见的方法 “;”分号用法 方式:command1 ; command2 用;号 ...
- 批量Insert
oracle INSERT ALL ,) ,) ,) FROM DUAL
- C++单链表类(带头结点)
Link.h #ifndef _LINK_0411 #define _LINK_0411 #include <string> #include <iostream> //定义数 ...
- 【原创】大叔经验分享(77)openresty(nginx+lua)发http请求
openresty(nginx+lua)发http请求 利用location+proxy_pass间接实现 location ^~ /test/http { internal; proxy_pass ...
- 深入理解Java自动装箱拆箱机制
1.自动装箱与拆箱的定义 装箱就是自动将基本数据类型转换为包装器类型(int-->Integer): 拆箱就是自动将包装器类型转换为基本数据类型(Integer-->int). Java中 ...