排序
【算法】【Python】好数
我的题解 def isGood(x): x = str(x) lenx = len(x) for i in range(lenx): # 奇数位 if i % 2 == 0: if int(x[-i-1]) % 2 == 0: return False else: if int(x[-i-1]) % 2 == 1: return False r...
【深进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 时,将...
【Python】datetime包
datetime 是 Python 内置的日期时间处理库,它包含了处理日期、时间、时间间隔等的类和函数。datetime 库可以从系统中获得时间,并以用户选择的格式输出。下面是 datetime 常用的类和函数以及它...
【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 <&...