排序
【模拟】旋转矩阵
#include<stdio.h> int main(){ int n; scanf('%d',&n); int a[n][n]; int top=0,down=n-1,left=0,right=n-1,count=1; while(count<=n*n){ for (int i=left;i<=right;i++){ a[top]...
【递归】斐波那契数
#include<iostream> using namespace std; int fib(int n){ if (n<2){ return n; } return fib(n-1) + fib(n-2); } int main(){ int n; cin >> n; cout << fib(n); return 0; } 数...
【递归】2的幂
递归法: class Solution: def isPowerOfTwo(self, n: int) -> bool: if n==1: return True if n<=0 or n%2!=0: return Fals...
【DP】使用最小花费爬楼梯
题目 给你一个整数数组 cost ,其中 cost[i] 是从楼梯第 i 个台阶向上爬需要支付的费用。一旦你支付此费用,即可选择向上爬一个或者两个台阶。 你可以选择从下标为 0 或下标为 1 的台阶开始爬楼...
【并查集】Python模板
题目描述 如题,现在有一个并查集,你需要完成合并和查询操作。 输入格式 第一行包含两个整数 N,M ,表示共有 N 个元素和 M 个操作。 接下来 M 行,每行包含三个整数 Zi,Xi,Yi 。 当 Zi=1 时,将...
【差分与前缀和】Python模板
N, Q = map(int,input().split()) nlist = list(map(int, input().split())) nlist.insert(0, 0) cf = [0 for _ in range(N+1)] print(nlist) for _ in range(Q): l,r,x = map(int, input()....