当前位置:网站首页>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
边栏推荐
- Promise
- Cve-2017-11882 reappearance
- Extracting profile data from profile measurement
- Room cannot create an SQLite connection to verify the queries
- 从 1.5 开始搭建一个微服务框架——调用链追踪 traceId
- 《编程之美》读书笔记
- Cannot resolve symbol error
- Comment faire votre propre robot
- Spark AQE
- Model analysis of establishment time and holding time
猜你喜欢

cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】

Notepad++ regular expression replacement string

Spark AQE

Calculate sha256 value of data or file based on crypto++

《强化学习周刊》第52期:Depth-CUPRL、DistSPECTRL & Double Deep Q-Network

Location based mobile terminal network video exploration app system documents + foreign language translation and original text + guidance records (8 weeks) + PPT + review + project source code
![[groovy] JSON serialization (convert class objects to JSON strings | convert using jsonbuilder | convert using jsonoutput | format JSON strings for output)](/img/52/021931181ad3f4bef271b4e98105c2.jpg)
[groovy] JSON serialization (convert class objects to JSON strings | convert using jsonbuilder | convert using jsonoutput | format JSON strings for output)

Comment faire votre propre robot

notepad++正则表达式替换字符串

State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.
随机推荐
云导DNS和知识科普以及课堂笔记
[groovy] compile time metaprogramming (compile time method injection | method injection using buildfromspec, buildfromstring, buildfromcode)
Novice entry depth learning | 3-6: optimizer optimizers
可恢复保险丝特性测试
How spark gets columns in dataframe --column, $, column, apply
免费的聊天机器人API
STM32 configuration after chip replacement and possible errors
常用API类及异常体系
Yolov5、Pycharm、Anaconda环境安装
How to use the flutter framework to develop and run small programs
Keepalive component cache does not take effect
Cannot resolve symbol error
Cve-2017-11882 reappearance
电机的简介
数据分析思维分析方法和业务知识——分析方法(二)
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
RAID disk redundancy queue
How to solve the problems caused by the import process of ecology9.0
Yolov5, pychar, Anaconda environment installation
Spark SQL null value, Nan judgment and processing