何成HN
何成HN
全部文章
分类
归档
标签
去牛客网
登录
/
注册
何成HN的博客
全部文章
(共409篇)
题解 | 舞萌时间到!
#格式化输入 s = input() q = int(input()) #字符数值字典,前缀和数组初始化 dx = dict(zip(['P','p','G','g','m'],[3,2,1,0,0])) ans, dp = 0, [] for c in s: ans += dx[c] ...
2025-11-13
0
20
题解 | 【模板】差分
n, m = map(int,input().split()) a = list(map(int,input().split())) b = [0]*(n+1)#计算差量数组 for _ in range(m): l, r, k = map(int,input().split()) ...
2025-11-13
0
15
题解 | 【模板】静态区间和(前缀和)
n, q = map(int,input().split()) a = list(map(int,input().split())) ans, dp = 0, [] for c in a:#制造前缀和列表 ans += c dp.append(ans) for _ in rang...
2025-11-13
0
27
题解 | 最大子段和
n = int(input()) a = list(map(int,input().split())) max_sum, cur_max= a[0], a[0]#最大子数组和,当前累计最大子数组和 for i in range(1,n): cur_max = max(a[i],cur_ma...
2025-10-29
0
26
题解 | 小红的地砖
n = int(input()) a = list(map(int,input().split())) if n==1:#只有一块砖,只有一种行走方式,一次走一步 print(a[n-1]) elif n==2:#只有两块砖,想要省力,只能一次走两步 print(a[n-1]) e...
2025-10-29
0
23
题解 | 小红闯关
import heapq#不用堆队列也可以做,但是会超时 n, k = map(int,input().split()) a = list(map(int,input().split())) total_time = sum(a) pq, saved_time = [], 0 for i in...
2025-10-29
0
27
题解 | 硬币凑钱
n = int(input()) coins = [1,5,7]#所有硬币的集合列表 INF = float('inf')#动态规划列表初始值位无穷大infinity dp = [float(INF)]*(n+1)#动态规划数组列表 dp[0] = 0#想要找零0元,只有0种方式 for coin ...
2025-10-28
0
33
题解 | 数楼梯
n = int(input()) dp = [0]*(n+1) if n==1:#只能一步到顶端,只有一种走法 print(1) elif n==2:#可以两种 print(2) else:#需要进行动态规划 dp[0], dp[1], dp[2] = 0, 1, 2 ...
2025-10-28
0
34
题解 | 小红的整数配对
n, k = map(int,input().split()) a = sorted(list(map(int,input().split()))) #数据输入及初始化 score, i = 0, n-1#分数,序号(从n-1开始) while i>0: if a[i]-a[i-1]&...
2025-10-28
0
26
题解 | 交换到最大
t = int(input()) for _ in range(t): s = list(input()) n = len(s) #从第i未开始固定最有价值的值,任何距离当前位置超过 9 的字符,移动过来的价值都必然是负数 for i in range(n): ...
2025-10-28
1
25
首页
上一页
16
17
18
19
20
21
22
23
24
25
下一页
末页