当前位置:网站首页>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
边栏推荐
- KDD 2022 | 脑电AI助力癫痫疾病诊断
- FPGA内部硬件结构与代码的关系
- 关于#数据库#的问题:(5)查询库存表中每本书的条码、位置和借阅的读者编号
- Extracting profile data from profile measurement
- Common API classes and exception systems
- Go learning --- structure to map[string]interface{}
- Intranet Security Learning (V) -- domain horizontal: SPN & RDP & Cobalt strike
- 如何制作自己的機器人
- Kotlin core programming - algebraic data types and pattern matching (3)
- The value of applet containers
猜你喜欢
LeetCode 1598. Folder operation log collector
cf:C. The Third Problem【关于排列这件事】
Atcoder beginer contest 258 [competition record]
State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.
Free chat robot API
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
Comment faire votre propre robot
Analysis of the combination of small program technology advantages and industrial Internet
The relationship between FPGA internal hardware structure and code
Browser reflow and redraw
随机推荐
uniapp开发,打包成H5部署到服务器
Cloud guide DNS, knowledge popularization and classroom notes
Atcoder beginer contest 254 [VP record]
Model analysis of establishment time and holding time
Codeforces round 804 (Div. 2) [competition record]
MIT doctoral thesis | robust and reliable intelligent system using neural symbol learning
Spark SQL空值Null,NaN判断和处理
NLP text processing: lemma [English] [put the deformation of various types of words into one form] [wet- > go; are- > be]
Calculate sha256 value of data or file based on crypto++
图解网络:TCP三次握手背后的原理,为啥两次握手不可以?
Yolov5、Pycharm、Anaconda环境安装
小程序容器可以发挥的价值
golang mqtt/stomp/nats/amqp
电机的简介
Extension and application of timestamp
MySQL存储引擎
cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】
Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?
[groovy] JSON string deserialization (use jsonslurper to deserialize JSON strings | construct related classes according to the map set)
Data analysis thinking analysis methods and business knowledge -- analysis methods (II)