当前位置:网站首页>Cf:h. maximum and [bit operation practice + K operations + maximum and]
Cf:h. maximum and [bit operation practice + K operations + maximum and]
2022-07-06 00:44:00 【White speed Dragon King's review】
analysis
and Just one 0 This position is still 0
So we count 31 individual bit Including 1 The number of
And then greed , From the highest position , As long as there is k Within, we will add ans in ( Add 2 ** i)
This is the bit operation expanded into dict, Then come down greedily from the highest position
Just get a high position , Just make money
So start from the top
ac code
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
bitDict = {
}
for i in range(31):
bitDict[i] = 0
for aa in a:
#print(bin(aa)[2:].zfill(31))
bin_str = (bin(aa)[2:].zfill(31))[::-1]
for i in range(31):
if bin_str[i] == '1':
bitDict[i] += 1
ans = 0
# greedy
for i in range(30, -1, -1):
# normal add 1
if k >= n - bitDict[i]:
ans += 2 ** i
k -= n - bitDict[i]
print(ans)
summary
An operation + and + greedy
边栏推荐
- MDK debug时设置数据实时更新
- Reading notes of the beauty of programming
- logstash清除sincedb_path上传记录,重传日志数据
- Codeforces gr19 D (think more about why the first-hand value range is 100, JLS yyds)
- 云导DNS和知识科普以及课堂笔记
- [Online gadgets] a collection of online gadgets that will be used in the development process
- Getting started with devkit
- Codeforces round 804 (Div. 2) [competition record]
- devkit入门
- State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.
猜你喜欢
How to solve the problems caused by the import process of ecology9.0
Model analysis of establishment time and holding time
[groovy] JSON string deserialization (use jsonslurper to deserialize JSON strings | construct related classes according to the map set)
MIT doctoral thesis | robust and reliable intelligent system using neural symbol learning
建立时间和保持时间的模型分析
State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.
XML配置文件
Anconda download + add Tsinghua +tensorflow installation +no module named 'tensorflow' +kernelrestart: restart failed, kernel restart failed
cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】
Idea远程提交spark任务到yarn集群
随机推荐
Natural language processing (NLP) - third party Library (Toolkit):allenlp [library for building various NLP models; based on pytorch]
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
Spark AQE
常用API类及异常体系
Calculate sha256 value of data or file based on crypto++
LeetCode 斐波那契序列
logstash清除sincedb_path上传记录,重传日志数据
电机的简介
How to use the flutter framework to develop and run small programs
Study diary: February 13, 2022
[Chongqing Guangdong education] reference materials for Zhengzhou Vocational College of finance, taxation and finance to play around the E-era
Browser reflow and redraw
图解网络:TCP三次握手背后的原理,为啥两次握手不可以?
小程序容器可以发挥的价值
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
Pointer - character pointer
Leetcode Fibonacci sequence
STM32按键消抖——入门状态机思维
golang mqtt/stomp/nats/amqp
Spark DF adds a column