XG0701
XG0701
全部文章
分类
题解(13)
归档
标签
去牛客网
登录
/
注册
XG0701的博客
全部文章
(共10篇)
题解 | 2024/10/15(滑动窗口 or 尺取法)(Python)
dic = {chr(i): 0 for i in range(ord('a'), ord('z') + 1)} s = input() left = 0; ans = len(s) for right, ch in enumerate(s): dic[ch] += 1 while...
Python3
滑动窗口
尺取法
2024-10-15
0
58
题解 | 2024/10/15(二维前缀和)(Python)
n, R = map(int, input().split()) a = [[0] * (5000 + 2) for _ in range(5000 + 2)] mx = my = R # 需要的边界 for _ in range(n): x, y, v = map(int, input(...
Python3
二维前缀和
2024-10-15
0
38
题解 | 2024/10/15(中位数贪心)(Python)
注意点: (1)最优位置是选在左中位数或右中位数处 (2)如果不在这两点,左右移动时增加的距离会大于减小的距离 N = int(input()) a = list(map(int, input().split())) a.sort() print(sum(abs(x - a[N // 2]) for...
Python3
贪心
2024-10-15
0
50
题解 | 2024/10/14(差分 + 前缀和 + 离散化)(Python)
L, M = map(int, input().split()) diff = [0] * (L + 2) for _ in range(M): left, right = map(int, input().split()) diff[left] += 1; diff[right +...
Python3
差分
前缀和
离散化
2024-10-14
0
46
题解 | 2024/10/14(差分 + 前缀和)(Python)
L, M = map(int, input().split()) diff = [0] * (L + 2) for _ in range(M): left, right = map(int, input().split()) diff[left] += 1; diff[right +...
Python3
差分
前缀和
2024-10-14
0
36
题解 | 2024/10/12(模拟)(Python)
注意点 (1)只需枚举年份以缩短时间复杂度 (2)闰年判定及二月天数的修改 def f(year: int) -> None: # 修改 2 月的天数 months[2] = 29 if year % 400 == 0: return if year ...
Python3
模拟
字符串
2024-10-12
0
91
题解 | 2024/10/12(模拟)(Python)
n = int(input()) lst = list() for _ in range(n): a, b, g, k = map(int, input().split()) lst.append((a, b, a + g, b + k)) x, y = map(int, inpu...
Python3
模拟
2024-10-12
0
55
题解 | 2024/10/11(模拟)(Python)
n = int(input()) a = list(map(int, input().split())) flag = False # 记录是否输出第一项 for i in range(n + 1): if a[i] == 0: continue # 输出连接号...
Python3
模拟
2024-10-11
0
69
题解 | 2024/10/11(队列 + 哈希表)(Python)
from collections import Counter, deque M, N = map(int, input().split()) cnt = Counter() # 哈希表 queue = deque() # 双端队列 ans = 0 # 统计查询次数 for ch in i...
Python3
队列
哈希表
2024-10-11
0
62
题解 | 2024/10/11(字符串 + 模拟)(Python)
p1, p2, p3 = map(int, input().split()) s = input() ans = "" for i, ch in enumerate(s): if ch == '-' and 0 < i < len(s) - 1: # 扩展 p...
Python3
字符串
模拟
2024-10-11
0
91