算法 第2页
令人头疼的算法,算法竞赛冲啊
【C++】四舍五入 - AI科研 编程 读书笔记 - 小竹の笔记本

【C++】四舍五入

#include <iostream> #include <cmath> using namespace std; float a[100000]; int main(){ int n; cin >> n; for (int i=0;i<n;i++){ cin >> a[i]; } for (int i=0;i<n;i++){ cou...
SmallBamboo的头像 - AI科研 编程 读书笔记 - 小竹の笔记本SmallBamboo2年前
01617
【递归】快速幂 - AI科研 编程 读书笔记 - 小竹の笔记本

【递归】快速幂

class Solution:    def myPow(self, x: float, n: int) -> float:        if n==0:            return 1        if n==1:            return x        if n==-1:  ...
SmallBamboo的头像 - AI科研 编程 读书笔记 - 小竹の笔记本SmallBamboo1年前
01509
【C】对一个分数约分 - AI科研 编程 读书笔记 - 小竹の笔记本

【C】对一个分数约分

int gcd(int a, int b) {    if (b == 0) {        return a;   } else {        return gcd(b, a % b);   } } void simplifyFraction(int *a, int *b) {    int divisor = gcd(*...
SmallBamboo的头像 - AI科研 编程 读书笔记 - 小竹の笔记本SmallBamboo2年前
01669
【算法】【Python】使用动态规划(DP)解决最长公共子序列(LCS)问题 - AI科研 编程 读书笔记 - 小竹の笔记本

【算法】【Python】使用动态规划(DP)解决最长公共子序列(LCS)问题

使用动态规划计算 LCS 长度后,从dp[m][n]回溯构造 LCS 字符串:若text1[i-1] == text2[j-1],加入 LCS 并向左上移动,否则向dp值较大的方向移动。最终反转 LCS 输出。时间复杂度 O(m×n)。
SmallBamboo的头像 - AI科研 编程 读书笔记 - 小竹の笔记本SmallBamboo6个月前
01135
【C++】过河卒问题 - AI科研 编程 读书笔记 - 小竹の笔记本

【C++】过河卒问题

无马情况 #include <iostream> // 定义棋盘大小 #define MAXSIZE 30 using namespace std; int main(){ int a[MAXSIZE][MAXSIZE]={0}; int n,m; // n,m为B点的坐标,A点默认为(0,0) cin >> n...
SmallBamboo的头像 - AI科研 编程 读书笔记 - 小竹の笔记本SmallBamboo1年前
015614
【C】时间差计算(表达式:运算符和算子,取余运算) - AI科研 编程 读书笔记 - 小竹の笔记本

【C】时间差计算(表达式:运算符和算子,取余运算)

时间差计算代码 //计算时间差 #include<stdio.h> int main() { int hour1,minute1,hour2,minute2; printf('请输入第一个时间\n'); scanf('%d %d', &hour1,&minute1); printf('请输入...
SmallBamboo的头像 - AI科研 编程 读书笔记 - 小竹の笔记本SmallBamboo2年前
04518