传送门

题意

给出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(位运算)的更多相关文章

  1. Tenka1 Programmer Beginner Contest D IntegerotS(补)

    当时没做出来,官方题解没看懂,就看别人提交的代码,刚对着别人代码调了几组数据,才发现,思路差不多,不过,原来是这样实现啊,果然我还是很菜 思路:题目要求是选取的这些数字全部进行OR运算,结果<= ...

  2. AtCoder Tenka1 Programmer Beginner Contest 解题报告

    赛时写了ABC,D实在没啥思路,然后C又难调...然后就从写完AB时的32名掉到了150+名 T_T 码力不够,思维不行,我还是AFO吧 比赛链接 A - Measure sb模拟,奇数串倒着输出偶数 ...

  3. AtCoder Beginner Contest 261E // 按位思考 + dp

    题目链接:E - Many Operations (atcoder.jp) 题意: 给定一个数x,以及n个操作(ti,ai): 当 t = 1 时,将 x & a 当 t = 2 时,将 x ...

  4. zoj--3870--Team Formation(位运算好题)

    Team Formation Time Limit: 3000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

  5. 【AtCoder】Tenka1 Programmer Contest 2019

    Tenka1 Programmer Contest 2019 C - Stones 题面大意:有一个01序列,改变一个位置上的值花费1,问变成没有0在1右边的序列花费最少多少 直接枚举前i个都变成0即 ...

  6. Tenka1 Programmer Contest D - Crossing

    链接 Tenka1 Programmer Contest D - Crossing 给定\(n\),要求构造\(k\)个集合\({S_k}\),使得\(1\)到\(n\)中每个元素均在集合中出现两次, ...

  7. Tenka1 Programmer Contest C - Align

    链接 Tenka1 Programmer Contest C - Align 给定一个序列,要求重新排列最大化\(\sum_{i=2}^{i=n} |a_i-a_{i-1}|\),\(n\leq 10 ...

  8. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  9. AtCoder Beginner Contest 173 题解

    AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...

随机推荐

  1. java开始到熟悉70-71

    本次内容:file类 package array; /** * file类 */ import java.io.File; import java.io.IOException; public cla ...

  2. Intel Chipsets

    http://en.wikipedia.org/wiki/Chipset Chipset From Wikipedia, the free encyclopedia     A chipset is ...

  3. hdu 4858 项目管理(vector模拟)

    # include <stdio.h> # include <algorithm> # include <string.h> # include <vecto ...

  4. UltraEdit中使用正则表达式-简单用法

    UltraEdit中使用正则表达式 1.认识正则表达式语法: 正则表达式 (UltraEdit Syntax): % 匹配行首 - 表明要搜索的字符串一定在行首. $ 匹配行尾 - 表明要搜索的字符串 ...

  5. iOS simulator+Appium

    Why are you trying to run iOS automation on a real device? That's a bad idea. iOS Automation on a re ...

  6. Swift开发教程--怎样播放图片动画

    废话少说,直接上代码: var barsAnim = UIImageView(frame: self.view.frame); barsAnim.animationImages = NSArray() ...

  7. python day- 10 动态参数 函数的嵌套 命名空间和作用域 global和nolocal

    一.动态参数: 动态参数是形参的一类 分为:动态位置参数(* + 函数名)表示 调用后返回的是元祖 动态关键字参数(** + 函数名)表示 形参的排列顺序: 位置参数     >   动态位置参 ...

  8. 在C++中使用Libmd5计算字符串或文件的MD5值

    CppMD5Demo.cpp #include <iostream> #include <fstream> #include <chrono> #include & ...

  9. mysql 数据库导入错误:40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET

    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;/*!40101 SET @OLD_CHARACTER_SET_RES ...

  10. Unity3D集成腾讯语音GVoice SDK

    友情提示:最近发现腾讯GVoice有另一个官网,叫做腾讯游戏服务,经过对比发现这个网站才是最新的,下面我介绍的那个估计是已经废弃的,但不知道为啥老的网站没有直接链接到新网址而是仍然保留了.不过新官网的 ...