当前位置:网站首页>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
边栏推荐
- Starting from 1.5, build a micro Service Framework - call chain tracking traceid
- MCU通过UART实现OTA在线升级流程
- Data analysis thinking analysis methods and business knowledge -- analysis methods (II)
- 关于#数据库#的问题:(5)查询库存表中每本书的条码、位置和借阅的读者编号
- 《编程之美》读书笔记
- Leetcode 44 Wildcard matching (2022.02.13)
- Kotlin core programming - algebraic data types and pattern matching (3)
- Getting started with devkit
- curlpost-php
- STM32 configuration after chip replacement and possible errors
猜你喜欢
Classic CTF topic about FTP protocol
Uniapp development, packaged as H5 and deployed to the server
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
可恢复保险丝特性测试
uniapp开发,打包成H5部署到服务器
[groovy] JSON serialization (convert class objects to JSON strings | convert using jsonbuilder | convert using jsonoutput | format JSON strings for output)
常用API类及异常体系
Opencv classic 100 questions
Comment faire votre propre robot
时间戳的拓展及应用实例
随机推荐
Single source shortest path exercise (I)
Spark AQE
程序员成长第九篇:真实项目中的注意事项
Spark-SQL UDF函数
Spark SQL null value, Nan judgment and processing
Reading notes of the beauty of programming
After Luke zettlemoyer, head of meta AI Seattle research | trillion parameters, will the large model continue to grow?
Notepad + + regular expression replace String
esxi的安装和使用
How spark gets columns in dataframe --column, $, column, apply
curlpost-php
孤勇者
LeetCode 1598. Folder operation log collector
MIT博士论文 | 使用神经符号学习的鲁棒可靠智能系统
Comment faire votre propre robot
Room cannot create an SQLite connection to verify the queries
An understanding of & array names
I'm interested in watching Tiktok live beyond concert
Codeforces gr19 D (think more about why the first-hand value range is 100, JLS yyds)
synchronized 和 ReentrantLock