算法 第3页
令人头疼的算法,算法竞赛冲啊
【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年前
01709
【递归】2的幂 - AI科研 编程 读书笔记 - 小竹の笔记本

【递归】2的幂

递归法: class Solution:    def isPowerOfTwo(self, n: int) -> bool:        if n==1:            return True        if n<=0 or n%2!=0:            return Fals...
SmallBamboo的头像 - AI科研 编程 读书笔记 - 小竹の笔记本SmallBamboo1年前
016811
【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年前
01667
【模拟】各位相加 - AI科研 编程 读书笔记 - 小竹の笔记本

【模拟】各位相加

#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 <&...
SmallBamboo的头像 - AI科研 编程 读书笔记 - 小竹の笔记本SmallBamboo1年前
01656
【深进1.例1】求区间和 - AI科研 编程 读书笔记 - 小竹の笔记本

【深进1.例1】求区间和

我学习了如何高效地求解区间和问题。对于给定的数列和多个查询区间,我通过预先计算一个前缀和数组,将每个区间的求和操作转化为两次数组查询和一次减法。这种方法将每次查询的时间复杂度从 O(n...
SmallBamboo的头像 - AI科研 编程 读书笔记 - 小竹の笔记本SmallBamboo1年前
01639
【C++】过河卒问题 - AI科研 编程 读书笔记 - 小竹の笔记本

【C++】过河卒问题

我通过动态规划方法解决了C++中的过河卒问题。我的方案首先考虑无马干扰的简化情况,路径数通过类似杨辉三角的递推计算。接着,我处理了有马的情况:在棋盘上标记出马及其所有控制点为障碍。在...
SmallBamboo的头像 - AI科研 编程 读书笔记 - 小竹の笔记本SmallBamboo1年前
016114