上一页 1 ··· 93 94 95 96 97 98 99 100 101 ··· 119 下一页
摘要: 一、概念 树的路径长度:树的路径长度是从树根到树中每一结点的路径长度之和。在结点数目相同的二叉树中,完全二叉树的路径长度最短。 结点的权:在一些应用中,赋予树中结点的一个有某种意义的实数。 结点的带权路径长度:结点到树根之间的路径长度与该结点上权的乘积。 树的带权路径长度(Weighted Path Length of Tree):定义为树中所有叶结点的带权路径长度之和,通常记为:其中: n表示叶子结点的数目 wi和li分别表示叶结点ki的权值和根到结点ki之间的路径长度。 树的带权路径长度亦称为树的代价。 哈夫曼树或最优二叉树:在权为wl,w2,…,w... 阅读全文
posted @ 2012-08-08 13:45 加拿大小哥哥 阅读(639) 评论(0) 推荐(0)
摘要: 一、定义 二叉查找(搜索)树(Binary Search Tree)。其定义为:二叉查找树或者是空树,或者是满足如下性质的二叉树: ①若它的左子树非空,则左子树上所有结点的值均小于根结点的值; ②若它的右子树非空,则右子树上所有结点的值均大于根结点的值; ③左、右子树本身又各是一棵二叉查找树。 上述性质简称二叉查找树性质(BST性质),故二叉查找树实际上是满足BST性质的二叉树。二、特点 由BST性质可得: (1) 二叉查找树中任一结点x,其左(右)子树中任一结点y(若存在)的关键字必小(大)于x的关键字。 (2) 二叉查找树中,各结点关键字是惟一的。注意:实际应用中,不能保... 阅读全文
posted @ 2012-08-08 13:30 加拿大小哥哥 阅读(881) 评论(0) 推荐(0)
摘要: #include <iostream>#include <string>using namespace std;typedef struct Node{ char data; Node *lchild,*rchild;}Node,*Bitree;Bitree creat(string s1,string s2){ if(s1.length()==0) return NULL; Node *root; root = new Node; root->data = s1[0];//第二次做,竟然忘家了 size_t pos = s2.fi... 阅读全文
posted @ 2012-08-08 09:21 加拿大小哥哥 阅读(355) 评论(0) 推荐(0)
摘要: #include <iostream>#include <string>#include <map>#include <iterator>#include <cstdio>using namespace std;int main(){ string s; int cnt=0; map<string,int> tree;//一对一映射 while(getline(cin,s)) { tree[s]++;//数组方式 cnt++; } map<string,int>::iterator iter; for(iter 阅读全文
posted @ 2012-08-07 23:44 加拿大小哥哥 阅读(641) 评论(0) 推荐(0)
摘要: //由先中序建树,然后后序遍历 #include <cstring>#include <string>#include <iostream>#include <cstdlib>using namespace std;typedef struct Node{ char data; Node *lchild,*rchild;}Node,*Bitree;Bitree creat(string s1,string s2){ if(s1.length()==0)//到叶子节点 return NULL; Node *root = new Node; if(! 阅读全文
posted @ 2012-08-07 13:19 加拿大小哥哥 阅读(256) 评论(2) 推荐(0)
摘要: /*字符串匹配,(模式串 主串)区分大小写*/ #include <cstdio>#include <cstring>#include <cstdlib>using namespace std;const int N = 100010;char str1[N],str2[N];bool is_match(){ int i,j; if(strlen(str1)>strlen(str2)) return false; for(j=i=0;str1[i]!='\0'&&str2[j]!='\0';j++) if 阅读全文
posted @ 2012-08-07 00:07 加拿大小哥哥 阅读(176) 评论(0) 推荐(0)
摘要: Round and Round We GoTime Limit: 1000MSMemory Limit: 10000KTotal Submissions: 10514Accepted: 4812DescriptionA cyclic number is an integer n digits in length which, when multiplied by any integer from 1 to n, yields a"cycle"of the digits of the original number. That is, if you consider the 阅读全文
posted @ 2012-08-06 23:06 加拿大小哥哥 阅读(724) 评论(0) 推荐(0)
摘要: #include <cstdio>#include <cstring>#include <cctype>#include <cstdlib>using namespace std;char str[210];int main(){ int i,j,k,T; char str0[10]; while(scanf("%s",str0),strcmp(str0,"ENDOFINPUT")) { getchar(); memset(str0,0,sizeof(str0)); memset(str,0,sizeof( 阅读全文
posted @ 2012-08-06 18:52 加拿大小哥哥 阅读(476) 评论(0) 推荐(0)
摘要: //原来忘了不可以数字开头,后来全部加上a #include <cstdio>#include <cstring>float area(float a1x,float a1y,float a2x,float a2y,float a3x,float a3y){ return 1.0/2*((a2x-a1x)*(a3y-a1y)-(a3x-a1x)*(a2y-a1y));}int main(){ int i,j,k,T; while(scanf("%d",&T),T) { int a1x,a1y,a2x,a2y,a3x,a3y; scanf(&q 阅读全文
posted @ 2012-08-06 15:12 加拿大小哥哥 阅读(344) 评论(0) 推荐(0)
摘要: int main(int argc, char * argv[]){……}参数argc就代表启动程序时,命令行参数的个数。C/C++语言规定,可执行程序程序本身的文件名,也算一个命令行参数,因此,argc的值至少是1。参数argv是一个数组,其中的每个元素都是一个char* 类型的指针,该指针指向一个字符串,这个字符串里就存放着命令行参数。argv[0]指向的字符串就是第一个命令行参数,即可执行程序的文件名argv[1]指向第二个命令行参数argv[2]指向第三个命令行参数……。#include <stdio.h>int main(int argc, char * argv[]){ 阅读全文
posted @ 2012-08-06 14:47 加拿大小哥哥 阅读(435) 评论(0) 推荐(0)
上一页 1 ··· 93 94 95 96 97 98 99 100 101 ··· 119 下一页