摘要: 数组存储二叉树(下标从1开始)。i 时父节点为i/2;当i 2= len) return ; printf("%c",a[i]); PreTra(i 2); PreTra(i 2+1); return ; } void InTra(int i){ if(i = len) return ; InTra 阅读全文
posted @ 2016-03-18 16:31 阿文的博客 阅读(243) 评论(0) 推荐(0) 编辑
摘要: ```cpp include include using namespace std; int f[102]; int found(int x){ return f[x] = f[x] == x ? x : found(f[x]); // if(x == f[x]) // return x; // 阅读全文
posted @ 2016-03-17 23:07 阿文的博客 阅读(94) 评论(0) 推荐(0) 编辑
摘要: ```cpp #include #include #include using namespace std; int next[1002],sublen,poslen; char sub[1002],pos[10002]; void get_next(){ int i,j; next[0] = -1; i = 0; j = -1; while(i = sublen) pri... 阅读全文
posted @ 2016-03-16 08:04 阿文的博客 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 题目大意:在一个数字串中找到连个连续的字串(这两个字串可以相邻),使得两个字串和最大。 思路:最大字串的变形。找出每个数字左边和最大的串,右边和最大的串, 然后左右相加算出最大的和。 代码如下: cpp include include include define MAX 0x6fffffff us 阅读全文
posted @ 2016-03-12 17:19 阿文的博客 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 题目大意:小明从杭州去往某目的地,要经过一些加油站,每个加油站的价格不一样。若能顺利到达,求加油费用最少为多少,否则求出能行驶的最远距离。 思路:贪心算法 1 若下一加油站的价格更便宜,则只需走到下一加油站即可。 2 若下一结点的价格没有该节点便宜 1.若将油箱加满,看看在其能到达的最远距离内,是否 阅读全文
posted @ 2016-03-12 17:11 阿文的博客 阅读(706) 评论(0) 推荐(0) 编辑
摘要: 十进制转换为其他进制 1 bin(6) 110 2 oct(9) 11 3 hex(17) 11 其他进制转换为十进制 1 int("111",2) 7 2 int("10",8) 8 3 int("10",16) 16 进制表示 1 0b11 3 2 0o10 8 3 010 8 4 0... 阅读全文
posted @ 2016-01-19 17:38 阿文的博客 阅读(143) 评论(0) 推荐(0) 编辑
摘要: for循环的使用 1 在list 或 dictionary 使用 list = [1,2,3,4,5,6] for i in list: list print(i) for item in dic: dictionary print(dic[item]) 2 使用range()函数,该函数... 阅读全文
posted @ 2016-01-15 20:24 阿文的博客 阅读(124) 评论(0) 推荐(0) 编辑
摘要: ```cpp #dictionary可以保存不同类型的值 menu = {'fish0':14.50} list = [] menu['fish1'] = 10.1 # Adding new key-value pair menu['fish2'] = 12.01 menu[12] = list list.append(123) #list中也可以保存不同类型的值 list.append(... 阅读全文
posted @ 2016-01-12 15:30 阿文的博客 阅读(198) 评论(0) 推荐(0) 编辑
摘要: ```cpp animals = ["aardvark", "badger", "duck", "emu", "fennec fox"] print(animals[1:3]) # print "badger" and "duck" duck_index = animals.index("duck") # Use index() to find "duck" animals.in... 阅读全文
posted @ 2016-01-11 22:17 阿文的博客 阅读(131) 评论(0) 推荐(0) 编辑
摘要: ```cpp # str = "AbCd" #以下示例均使用该字符串 截取: print(str[1:3]) #输出"bC" 转小写: print(str.lower()) #输出"abcd" 转大写: print(str.upper()) #输出"ABCD" 长度: print(len(str)) #输出4 选择满足某些条件的值 1> ... 阅读全文
posted @ 2016-01-11 21:57 阿文的博客 阅读(138) 评论(0) 推荐(0) 编辑