Tenka1 Programmer Beginner Contest D - IntegerotS(位运算)
传送门
题意
给出N,K,给出N对数a[i],b[i],选择一些数使得or和小于k且\(max\sum b[i]\)
分析
枚举k的每一个1位,将其删去并让低位全为1,对于每一个这样的数c,如果a[i]|c==c,那么就加上b[i],最后取最大值即可
trick
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))
int n, k;
int a[100100], b[100100];
ll ans, ret;
int c;
int main()
{
cin >> n >> k;
F(i, 1, n) scanf("%d %d", a + i, b + i);
ans = 0;
F(i, 1, n)
{
if ((a[i] | k) == k) ans += b[i];
}
F(i, 0, 30)if ((1 << i)&k)
{
c = (k - (1 << i)) | ((1 << i) - 1);
ll ret = 0;
F(j, 1, n) if ((c | a[j]) == c) ret += b[j];
ans = max(ans, ret);
}
cout << ans << endl;
return 0;
}
Tenka1 Programmer Beginner Contest D - IntegerotS(位运算)的更多相关文章
- Tenka1 Programmer Beginner Contest D IntegerotS(补)
当时没做出来,官方题解没看懂,就看别人提交的代码,刚对着别人代码调了几组数据,才发现,思路差不多,不过,原来是这样实现啊,果然我还是很菜 思路:题目要求是选取的这些数字全部进行OR运算,结果<= ...
- AtCoder Tenka1 Programmer Beginner Contest 解题报告
赛时写了ABC,D实在没啥思路,然后C又难调...然后就从写完AB时的32名掉到了150+名 T_T 码力不够,思维不行,我还是AFO吧 比赛链接 A - Measure sb模拟,奇数串倒着输出偶数 ...
- AtCoder Beginner Contest 261E // 按位思考 + dp
题目链接:E - Many Operations (atcoder.jp) 题意: 给定一个数x,以及n个操作(ti,ai): 当 t = 1 时,将 x & a 当 t = 2 时,将 x ...
- zoj--3870--Team Formation(位运算好题)
Team Formation Time Limit: 3000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- 【AtCoder】Tenka1 Programmer Contest 2019
Tenka1 Programmer Contest 2019 C - Stones 题面大意:有一个01序列,改变一个位置上的值花费1,问变成没有0在1右边的序列花费最少多少 直接枚举前i个都变成0即 ...
- Tenka1 Programmer Contest D - Crossing
链接 Tenka1 Programmer Contest D - Crossing 给定\(n\),要求构造\(k\)个集合\({S_k}\),使得\(1\)到\(n\)中每个元素均在集合中出现两次, ...
- Tenka1 Programmer Contest C - Align
链接 Tenka1 Programmer Contest C - Align 给定一个序列,要求重新排列最大化\(\sum_{i=2}^{i=n} |a_i-a_{i-1}|\),\(n\leq 10 ...
- AtCoder Beginner Contest 153 题解
目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...
- AtCoder Beginner Contest 173 题解
AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...
随机推荐
- 当 外部 input 值的改变,获取 当前 input type="hidden" 的值
1.如何用jquery获取<input id="test" name="test" type="text"/>中输入的值? 方法 ...
- Android Studio——gradle同步出错:MALFORMED
Android Studio之前使用本地的gradle-2.10,而后创建新的工程总是报错,信息如下: Gradle sync failed: MALFORMED 而后在File->Projec ...
- Intel Naming Strategy--1
http://en.wikipedia.org/wiki/Mobile_Internet_device Computer sizes Classes of computers Larger S ...
- Python - colour-science库
http://nbviewer.jupyter.org/github/colour-science/colour-ipython/blob/master/notebooks/colour.ipynb# ...
- 获取Wifi密码,不知道是不是真的
package com.example.wifipassword; import java.util.List; import android.app.Activity; import android ...
- org.hibernate.id.IdentifierGenerationException错误解决方法
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before ...
- Kafka知识点汇总
整体结构 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZXJpY19zdW5haA==/font/5a6L5L2T/fontsize/400/fill/I ...
- HDOJ1004 数组还要自己初始化
#include <iostream> #include <stdio.h> #include "string.h"using namespace std; ...
- HDU 6143 Killer Names DP+快速密
Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human apprentice ...
- SequenceFileInputFormat区别TextInputFormat
通过InputFormat,Hadoop可以: l 检查MapReduce输入数据的正确性: l 将输入数据切分为逻辑块InputSplit,这些块会分配给Ma ...