当前位置:网站首页>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
边栏推荐
- [groovy] compile time metaprogramming (compile time method injection | method injection using buildfromspec, buildfromstring, buildfromcode)
- MCU realizes OTA online upgrade process through UART
- NLP text processing: lemma [English] [put the deformation of various types of words into one form] [wet- > go; are- > be]
- Yolov5、Pycharm、Anaconda环境安装
- 2022-02-13 work record -- PHP parsing rich text
- Spark SQL null value, Nan judgment and processing
- FPGA内部硬件结构与代码的关系
- I'm interested in watching Tiktok live beyond concert
- 几百行代码实现一个 JSON 解析器
- Arduino hexapod robot
猜你喜欢
notepad++正則錶達式替換字符串
FFmpeg抓取RTSP图像进行图像分析
可恢复保险丝特性测试
How to use the flutter framework to develop and run small programs
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
电机的简介
小程序技术优势与产业互联网相结合的分析
Browser reflow and redraw
免费的聊天机器人API
Leetcode:20220213 week race (less bugs, top 10% 555)
随机推荐
Novice entry depth learning | 3-6: optimizer optimizers
几百行代码实现一个 JSON 解析器
Folding and sinking sand -- weekly record of ETF
图解网络:TCP三次握手背后的原理,为啥两次握手不可以?
Notepad + + regular expression replace String
Basic introduction and source code analysis of webrtc threads
Lone brave man
关于#数据库#的问题:(5)查询库存表中每本书的条码、位置和借阅的读者编号
The value of applet containers
Yolov5、Pycharm、Anaconda环境安装
Problems and solutions of converting date into specified string in date class
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
MySQL存储引擎
Spark SQL空值Null,NaN判断和处理
Reading notes of the beauty of programming
Date类中日期转成指定字符串出现的问题及解决方法
《编程之美》读书笔记
Starting from 1.5, build a micro Service Framework - call chain tracking traceid
[groovy] JSON serialization (convert class objects to JSON strings | convert using jsonbuilder | convert using jsonoutput | format JSON strings for output)
MDK debug时设置数据实时更新