递归与递推
递归实现指数型枚举
1 | n = int(input()) |
递归实现排列型枚举
1 | n = int(input()) |
递归实现组合型枚举
1 | n, m = map(int, input().split()) |
带分数
1 | n = int(input()) |
简单斐波那契
1 | n = int(input()) |
费解的开关
1 | t = int(input()) |
翻硬币
1 | a, b = list(input()), list(input()) |
飞行员兄弟
1 | g = [list(input()) for _ in range(4)] |
二分与前缀和
数的范围
1 | n, q = map(int, input().split()) |
bisect
1 | import bisect |
数的三次方根
1 | n = float(input()) |
机器人跳跃问题
1 | n = int(input()) |
四平方和
暴力
1 | import math |
哈希表
1 | n = int(input()) |
分巧克力
1 | n, k = map(int, input().split()) |
前缀和
1 | n, m = map(int, input().split()) |
子矩阵的和
1 | from sys import stdin |
激光炸弹
1 | cnt, r = map(int, input().split()) |
K倍区间
1 | n, k = map(int, input().split()) |
数学与简单DP
买不到的数目
暴力
1 | n, m = map(int, input().split()) |
优化
1 | n, m = map(int, input().split()) |
公式
1 | n, m = map(int, input().split()) |
蚂蚁感冒
1 | n = int(input()) |
饮料换购
1 | n = int(input()) |
背包问题
1 | n, v = map(int, input().split()) |
摘花生
1 | t = int(input()) |
最长上升子序列
1 | n = int(input()) |
地宫取宝
1 | n, m, k = map(int, input().split()) |
波动数列
1 | n, s, a, b = map(int, input().split()) |
枚举、模拟与排序
连号区间数
1 | n = int(input()) |
递增三元组
前缀和
1 | n = int(input()) |
二分
1 | import bisect |
特别数的和
1 | n = int(input()) |
错误票据
1 | n = int(input()) |
回文日期
1 | date1, date2 = input(), input() |
移动距离
1 | w, m, n = map(int, input().split()) |
日期问题
1 | from time import strptime |
航班时间
1 | t = int(input()) |
外卖店优先级
1 | n, m, t = map(int, input().split()) |
归并排序
1 | n = int(input()) |
逆序对的数量
1 | n = int(input()) |
树状数组与线段树
动态求连续区间和
树状数组
1 | n, m = map(int, input().split()) |
线段树
1 | n, m = map(int, input().split()) |
数星星
1 | n = int(input()) |
数列区间最大值
dp(爆空间)
1 | n, m = map(int, input().split()) |
线段树(TLE)
1 | n, m = map(int, input().split()) |
小朋友排队
1 | N = 1000001 |
油漆面积
1 | 线段树 |
三体攻击
二分 + 三维差分 (难)
1 | from sys import stdin |
差分
1 | n, m = map(int, input().split()) |
差分矩阵
1 | n, m, q = map(int, input().split()) |
螺旋折线
1 | x, y = map(int, input().split()) |
双指针、BFS与图论
日志统计
1 | n, d, k = map(int, input().split()) |
献给阿尔吉侬的花束
1 | from collections import deque |
红与黑
dfs
1 | dirs = [(0, 1), (1, 0), (0, -1), (-1, 0)] |
bfs
1 | from collections import deque |
交换瓶子
贪心
1 | n = int(input()) |
并查集
1 | n = int(input()) |
完全二叉树的权值
前缀和
1 | n = int(input()) |
地牢大师
1 | from collections import deque |
全球变暖
1 | from collections import deque |
大臣的旅费
dfs(爆栈)
1 | import sys |
bfs
1 | from collections import deque |
贪心
股票买卖 II
1 | n = int(input()) |
货仓选址
1 | n = int(input()) |
糖果传递
1 | n = int(input()) |
1 | n = int(input()) |
雷达设备
1 | n, d = map(int, input().split()) |
付账问题
1 | n, s = map(int, input().split()) |
乘积最大
1 | n, k = map(int, input().split()) |
后缀表达式
1 | n, m = map(int, input().split()) |
灵能传输
1 | t = int(input()) |
数论
等差数列
1 | n = int(input()) |
X的因子链
1 | N = (1 << 20) + 10 |
聪明的燕姿
1 | N = 50000 |
五指山
1 | t = int(input()) |
最大比例
1 | n = int(input()) |
C 循环
1 | def exgcd(a, b): |
正则问题
1 | s = input().strip() |
糖果
IDA*
1 | def lowbit(x): |
dp
1 | n, m, k = map(int, input().split()) |
复杂DP
鸣人的影分身
1 | t = int(input()) |
糖果
1 | n, k = map(int, input().split()) |
密码脱落
1 | s = input() |
生命之树
1 | import sys |
包子凑数
1 | n = int(input()) |
括号配对
1 | s = input() |
斐波那契前 n 项和
1 | n, m = map(int, input().split()) |
垒骰子
1 | n, m = map(int, input().split()) |
疑难杂题
修改数组
1 | import sys |
倍数问题
1 | n, K = map(int, input().split()) |
组合数问题
1 | t, k = map(int, input().split()) |
模拟散列表
1 | n = int(input()) |