上一页 1 2 3 4 5 6 7 8 9 ··· 40 下一页

2014年4月7日

《算法导论》笔记 第6章 6.2保持堆的性质

摘要: 【笔记】当 MAX_HEAPIFY(A, i) 被调用时,我们假定LEFT(i)、RIGHT(i)为根的两棵二叉树都是最大堆。若子结点中有最大元素,将 A[i] 与其交换,对该子树调用 MAX_HEAPIFY。若 A[ i ] 为最大元素,结束循环。MAX_HEAPIFY 作用于一个高度为 h 的结点所需的运行时间为 O(h)。 void maxHeapify(int i) { int l = left(i); int r = right(i); int largest = i; if (l A[largest]) largest... 阅读全文

posted @ 2014-04-07 09:04 电子幼体 阅读(354) 评论(0) 推荐(0) 编辑

2014年4月6日

《算法导论》笔记 第6章 6.1堆

摘要: 【笔记】堆是一棵完全二叉树,树的根为 A[ 1 ] ,给定某个节点的下标 i , 其父节点为 i/2 、左儿子为 i*2 、右儿子为 i*2+1。二叉堆有两种,最大堆、最小堆(或称大根堆、小根堆)。大根堆中 A[ PARENT(i) ] >= A[ i ] , 最大元素在根部。结点在根部的高度定义为从本结点到叶子的最长简单下降路径上边的数目。堆的高度为树的根的高度。【练习】6.1-1 在高度为h的堆中,最多和最少的元素个数是多少?最多:最少:6.1-2 证明:含n个元素的堆的高度为 logn6.1-3 证明:在一个最大堆的某棵子树中,最大元素在该子树的根上。假设存在一个子树,其最大元素不 阅读全文

posted @ 2014-04-06 21:41 电子幼体 阅读(220) 评论(0) 推荐(0) 编辑

2014年3月26日

【python】__all__

摘要: __all__ 用于限制模块的导入from module import *若 module 中定义了__all__ 属性,则只有 __all__ 中指定的内容被导入。否则导入 module 中的所有内容。 阅读全文

posted @ 2014-03-26 19:16 电子幼体 阅读(114) 评论(0) 推荐(0) 编辑

【python】optparse 模块

摘要: Python 有两个内建的模块用于处理命令行参数:一个是 getopt,《Deep in python》一书中也有提到,只能简单处理 命令行参数;另一个是 optparse,它功能强大,而且易于使用,可以方便地生成标准的、符合Unix/Posix 规范的命令行说明。示例下面是一个使用 optparse 的简单示例:Python代码fromoptparseimportOptionParser[...]parser=OptionParser()parser.add_option("-f","--file",dest="filename", 阅读全文

posted @ 2014-03-26 18:58 电子幼体 阅读(185) 评论(0) 推荐(0) 编辑

2014年3月18日

【python】比较字符串中不同的地方

摘要: 题目来自 hacker.org 的Challenge 'Didactic Text' [Crypto]分析给出的文章,找出暗语。Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all the men are created equal.Now we are engaged in a great civil war, testing 阅读全文

posted @ 2014-03-18 20:55 电子幼体 阅读(4014) 评论(0) 推荐(0) 编辑

【python】将01组成的密码用ASCII编码成字符串

摘要: 题目来自 hacker.org 的Challenge 'Didactic Bytes' [Crypto]给出一个01串组成的密码,求出破译后的单词01110101 01110011 01100101 00100000 01110111 01100101 01100100 01101110 01100101 01110011 01100100 01100001 01111001 00100000 01100110 01101111 01110010 00100000 01110100 01101000 01100101 00100000 01100001 01101110 011 阅读全文

posted @ 2014-03-18 19:20 电子幼体 阅读(781) 评论(0) 推荐(0) 编辑

【python】统计文本中出现最多次的单词

摘要: 题目来自 hacker.org 中的Challenge '3280' [Coding] 。要求找出RFC 3280 中出现次数最多的长度为9的单词。将 RFC 3280 的文本并保存到本地后用如下代码进行处理。----import retext = open("in.txt",'r').read()words = re.split('[^a-zA-Z]',text) di = {}for word in words: if len(word)==9: di.setdefault(word,0) di[word]+=1res = 阅读全文

posted @ 2014-03-18 18:46 电子幼体 阅读(1317) 评论(0) 推荐(0) 编辑

2014年3月9日

争做python小能手(一)

摘要: 通过在 Codeforces 上用 Python 过题来增加对 python 的理解。------------------------------------CodeForces 208A--s = raw_input()a = s.split('WUB')for t in a: if t!='': print t,--1、 raw_input()读取一行输入作为字符串,一般配合split()作为读取数据2、str.split(str="", num=string.count(str)) 该方法返回字符串中的所有单词的列表,使用str作为分隔 阅读全文

posted @ 2014-03-09 15:22 电子幼体 阅读(174) 评论(0) 推荐(0) 编辑

2014年2月26日

URAL 1742 Team building 强联通

摘要: 每个人到他认为最强的人连一条边。缩点后,入度为0的点是最小解,强联通分量是最大解。---const int maxn=111100;const int maxm=210000;int n;struct Node { int to,next;} edges[maxm];int head[maxn],edge;void addedge(int u,int v) { edges[edge].to=v,edges[edge].next=head[u],head[u]=edge++;}void prepare() { memset(head,-1,sizeof head); ed... 阅读全文

posted @ 2014-02-26 11:13 电子幼体 阅读(142) 评论(0) 推荐(0) 编辑

ZOJ 3156 Taxi 二分二分图

摘要: ----------const int maxn=411;const int maxm=141011;int n,m;double x[maxn],y[maxn];double a[maxn][maxn];double disTo(int i,int j) { return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));}double dis[maxn*maxn];int cnt;double T;VI g[maxn];int from[maxn],tot;bool use[maxn];bool match(int u) { ... 阅读全文

posted @ 2014-02-26 11:10 电子幼体 阅读(125) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 9 ··· 40 下一页

导航