当前位置:网站首页>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
边栏推荐
- MIT博士论文 | 使用神经符号学习的鲁棒可靠智能系统
- RAID disk redundancy queue
- golang mqtt/stomp/nats/amqp
- 小程序容器可以发挥的价值
- Data analysis thinking analysis methods and business knowledge -- analysis methods (II)
- [Chongqing Guangdong education] Chongqing Engineering Vocational and Technical College
- 关于#数据库#的问题:(5)查询库存表中每本书的条码、位置和借阅的读者编号
- [Chongqing Guangdong education] reference materials for Zhengzhou Vocational College of finance, taxation and finance to play around the E-era
- [groovy] JSON string deserialization (use jsonslurper to deserialize JSON strings | construct related classes according to the map set)
- 【线上小工具】开发过程中会用到的线上小工具合集
猜你喜欢
Notepad + + regular expression replace String
SAP Spartacus home 页面读取 product 数据的请求的 population 逻辑
vSphere实现虚拟机迁移
Idea remotely submits spark tasks to the yarn cluster
2022-02-13 work record -- PHP parsing rich text
Date类中日期转成指定字符串出现的问题及解决方法
How to make your own robot
LeetCode 1189. Maximum number of "balloons"
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
Study diary: February 13, 2022
随机推荐
Cloud guide DNS, knowledge popularization and classroom notes
Set data real-time update during MDK debug
【EI会议分享】2022年第三届智能制造与自动化前沿国际会议(CFIMA 2022)
Data analysis thinking analysis methods and business knowledge -- analysis methods (II)
KDD 2022 | EEG AI helps diagnose epilepsy
几百行代码实现一个 JSON 解析器
Curlpost PHP
Extracting profile data from profile measurement
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
Model analysis of establishment time and holding time
电机的简介
Free chat robot API
Beginner redis
MDK debug时设置数据实时更新
Anconda download + add Tsinghua +tensorflow installation +no module named 'tensorflow' +kernelrestart: restart failed, kernel restart failed
Room cannot create an SQLite connection to verify the queries
OpenCV经典100题
Spark SQL UDF function
MySQL存储引擎
时间戳的拓展及应用实例