当前位置:网站首页>codeforce:A. Doremy‘s IQ【反向贪心】
codeforce:A. Doremy‘s IQ【反向贪心】
2022-07-17 18:13:00 【白速龙王的回眸】

分析
所谓贪心,要么正向要么反向
反正都是on的
这道题而言,我们知道最后的iq肯定是最低的,不妨从0开始
从最后开始反序贪心
如果当前的iq都大于ai,就直接设置成1
如果当前的iq小于一开始的q,让当前iq+1,再设置成1
最后情况就是iq已经等于一开始的q,但还是ai大于iq,但就无可奈何
ac code
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, q = list(map(int, input().split()))
a = list(map(int, input().split()))
b = ['0'] * n
rest_q = 0
# reverse + greedy
for i in range(n - 1, -1, -1):
# greedy
if rest_q >= a[i]:
b[i] = '1'
# can add
elif rest_q < q and a[i] > rest_q:
rest_q += 1
b[i] = '1'
# do nothing
else:
pass
print(''.join(b))
总结
贪心总有妙用
因为后面的iq会限制选法,所以我们不妨从后面开始贪心
边栏推荐
- Realize automatic logging
- 面试官:可以接受转Go吗?
- MatrixCube揭秘 101——MatrixCube的功能与架构
- LeetCode 0118. 杨辉三角
- 【Pygame 学习笔记】6.Cursor 鼠标光标
- What are the pain points of collaborative tools collaborative office management
- 最小交換次數
- Basic database operations in MySQL
- Mycat2 builds MySQL master-slave separation
- AI is the designer who knows you best? Let users generate digital clothing "by heart" Adidas ozworld
猜你喜欢

【js逆向爬虫】-有道翻译js逆向实战

2.三数之和

Security measures for tcp/ip protocol vulnerabilities

Panasonic A6 servo driver external absolute value grating ruler full closed loop parameter setting

El table column drag and drop (no need to introduce other plug-ins)
![[pyGame learning notes] 6 Cursor mouse cursor](/img/ea/70fb3043ae32eca68e31144a54b651.jpg)
[pyGame learning notes] 6 Cursor mouse cursor

Audio common terminal anatomy - never make a mistake again
[email protected] Cobalt iron bimetallic organic skeleton cox/mil-100 (FE) | [email protected]

LeetCode 0117. 填充每个节点的下一个右侧节点指针 II

力扣413-等差数列划分——动态规划
随机推荐
Interview difficulties: difficulties in implementing distributed session, this is enough!
Li Kou 413 division of equal difference sequence dynamic programming
【Pygame 学习笔记】5.rect对象的碰撞检测
Brief analysis of circuit fault
JS operation string string string
Use golang to correctly process the IP data of the five major Internet registration agencies
STL string查找子串
LeetCode 0118. Yanghui triangle
如何优雅的升级 Flink Job?
Is it safe for Everbright futures to open an account online? Are there any account opening guidelines?
深度梳理:机器学习建模调参方法总结
Equivalent domain name
Cloud health management system based on STM32 (using Alibaba cloud Internet of things platform)
XML modeling (easy to learn)
AE如何制作星云粒子特效
Uio-66 - (COOH) 2 modified polyamide nanofiltration membrane | zif-8/pvp composite nanofiber membrane | uio-66-nh2 modified polyamide nanofiltration membrane
弘业期货网上开户安全吗?有没有开户指引?
運維小白成長記—架構第6周
El table column drag and drop (no need to introduce other plug-ins)
力扣64-最小路径和——动态规划入门题型