摘要: 博客地址:https://www.cnblogs.com/zylyehuo/ # -*- coding: utf-8 -*- """ 利用欧几里得算法实现一个分数类,支持分数的四则运算(加法) """ class Fraction: def __init__(self, a, b): self.a 阅读全文
posted @ 2023-08-19 23:38 zylyehuo 阅读(12) 评论(0) 推荐(0) 编辑
摘要: 博客地址:https://www.cnblogs.com/zylyehuo/ # -*- coding: utf-8 -*- # 递归 def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) print(gcd(12, 16)) # 阅读全文
posted @ 2023-08-19 20:38 zylyehuo 阅读(10) 评论(0) 推荐(0) 编辑
摘要: 博客地址:https://www.cnblogs.com/zylyehuo/ # -*- coding: utf-8 -*- # 最长公共子序列的长度 def lcs_length(x, y): m = len(x) n = len(y) c = [[0 for _ in range(n + 1)] 阅读全文
posted @ 2023-08-19 20:23 zylyehuo 阅读(7) 评论(0) 推荐(0) 编辑
摘要: 博客地址:https://www.cnblogs.com/zylyehuo/ # -*- coding: utf-8 -*- import time def cal_time(func): def wrapper(*args, **kwargs): t1 = time.time() result = 阅读全文
posted @ 2023-08-19 18:36 zylyehuo 阅读(9) 评论(0) 推荐(0) 编辑
摘要: 博客地址:https://www.cnblogs.com/zylyehuo/ # -*- coding: utf-8 -*- # 子问题的重复计算--递归方法--执行效率低 def fibnacci(n): if n == 1 or n == 2: return 1 else: return fib 阅读全文
posted @ 2023-08-19 12:44 zylyehuo 阅读(10) 评论(0) 推荐(0) 编辑
摘要: 博客地址:https://www.cnblogs.com/zylyehuo/ # -*- coding: utf-8 -*- def activity_selection(a): res = [a[0]] for i in range(1, len(a)): if a[i][0] >= res[-1 阅读全文
posted @ 2023-08-19 10:52 zylyehuo 阅读(7) 评论(0) 推荐(0) 编辑
摘要: 博客地址:https://www.cnblogs.com/zylyehuo/ # -*- coding: utf-8 -*- from functools import cmp_to_key def xy_cmp(x, y): if x + y < y + x: return 1 # 表示 x>y 阅读全文
posted @ 2023-08-19 10:33 zylyehuo 阅读(8) 评论(0) 推荐(0) 编辑