算法
爱你一Seng
这个作者很懒,什么都没留下…
展开
-
著名的斐波拉契数列(Fibonacci),除第一个和第二个数外,任意一个数都可由前两个数相加得到: 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
def fib(max): n, a, b = 0, 0, 1 while n < max: print(b) a, b = b, a + b n = n + 1 return 'done' 注意,赋值语句: a, b = b, a + b 相当于: t = (b, a + b) # t是一个tuple...原创 2018-09-08 09:34:20 · 1259 阅读 · 0 评论 -
斐波那契C++实现
#include<iostream> #include<vector> using namespace std; void fib(int max) { vector<int>v; v.push_back(1); v.push_back(1); int c; for (int i = 2; i < max; i++...原创 2018-09-08 10:18:45 · 1372 阅读 · 0 评论 -
杨辉三角python
def trangles(): L = [1] # 初始值 while True: yield(L) maxIndex = len(L)-1 # 最大下标,下标从0开始 # range(0,n)时,取的是0~(n-1)范围的数 # 第二次获取时,len=1,range(0)=[],因此k=[],L=[1,1] ...原创 2018-09-08 11:12:18 · 122 阅读 · 0 评论 -
回数是指从左向右读和从右向左读都是一样的数,例如12321,909。请利用filter()筛选出回数
k = str(n) return k == k[::-1]转载 2018-09-08 15:48:02 · 1796 阅读 · 1 评论 -
汉诺塔问题python
def move(n,a,b,c): if n==1: print(a,'-->',c) else: move(n-1,a,c,b) move(1,a,b,c) move(n-1,b,c,a) print(move(3,'A','B','C')) # 期待输出: # A --> C # A -->...原创 2018-09-07 12:43:16 · 399 阅读 · 0 评论 -
二叉树的创建与实现
#include <iostream> #include<cstdio> #include<cstdlib> using namespace std; typedef int TelemType;//TelemType代替int typedef struct BinaryTreeNode { TelemType data; struct B...原创 2018-10-23 19:52:22 · 782 阅读 · 1 评论