排序
【深进1.例1】求区间和
题目描述 给定 $n$ 个正整数组成的数列 $a_1, a_2, \cdots, a_n$ 和 $m$ 个区间 $[l_i,r_i]$,分别求这 $m$ 个区间的区间和。 对于所有测试数据,$n,m\le10^5,a_i\le 10^4$ 输入格式 第一行,为...
【差分与前缀和】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()....
【并查集】Python模板
题目描述 如题,现在有一个并查集,你需要完成合并和查询操作。 输入格式 第一行包含两个整数 N,M ,表示共有 N 个元素和 M 个操作。 接下来 M 行,每行包含三个整数 Zi,Xi,Yi 。 当 Zi=1 时,将...
【DP】使用最小花费爬楼梯
题目 给你一个整数数组 cost ,其中 cost[i] 是从楼梯第 i 个台阶向上爬需要支付的费用。一旦你支付此费用,即可选择向上爬一个或者两个台阶。 你可以选择从下标为 0 或下标为 1 的台阶开始爬楼...
【模拟】回文日期
题目 我的代码 import datetime ipt = input() begin = datetime.datetime(int(ipt[0:4]), int(ipt[4:6]), int(ipt[6:8])) flag1=0 flag2=0 while True: if flag1==1 and flag2==1: brea...
【递归】快速幂
class Solution: def myPow(self, x: float, n: int) -> float: if n==0: return 1 if n==1: return x if n==-1: ...
【递归】2的幂
递归法: class Solution: def isPowerOfTwo(self, n: int) -> bool: if n==1: return True if n<=0 or n%2!=0: return Fals...
【递归】斐波那契数
#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; } 数...
【模拟】旋转矩阵
#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 main(){ int num; cin >> num; while(num>9){ int total=0; while(num!=0){ total+=num%10; num/=10; } num = total; total = 0; } cout <&...
【模拟】二进制求和
#include <iostream> using namespace std; string addBinary(string a, string b){ string res; int carry = 0; // 进位 int i = a.size() - 1; int j = b.size() - 1; while(i >= 0 || j...
【C++】高精度减法
#include <iostream> using namespace std; int main(){ string s1,s2; cin >> s1; cin >> s2; int a1[210]={0}; int a2[210]={0}; int a3[210]={0}; char flag='+'; if (s1.size()<s2.si...