pat-a-树
文章平均质量分 64
要认认真真
这个作者很懒,什么都没留下…
展开
-
1020. Tree Traversals (25)
点击打开链接 #include #include using namespace std; #define MAX 40 struct node{ int data; int lchild; int rchild; }tree[MAX]; int post[MAX]; int in[MAX]; int n; int index=0; int newNode(){ tree[原创 2015-01-30 10:28:03 · 171 阅读 · 0 评论 -
1064. Complete Binary Search Tree (30)
点击打开链接 由完全二叉树和二叉搜索树构造出二叉树,然后层次遍历 先画出完全二叉树的模样,即确定左右孩子,因为都存储的是序号,左孩子为2*i,右孩子为2*i+1 由于bst中序遍历为有序的,因此中序遍历时确定data值 #include #include using namespace std; #define MAX 10010 struct no{ int da原创 2015-02-01 17:25:14 · 197 阅读 · 0 评论 -
1090. Highest Price in Supply Chain (25)
点击打开链接 与1079类似 数据大,用bfs #include #include #include #include using namespace std; #define MAX 100010 struct no{ int layer; vector next; }node[MAX]; int n; double p,r; int root; void bfs(原创 2015-01-31 09:44:29 · 316 阅读 · 0 评论 -
1004. Counting Leaves (30)
点击打开链接 #include #include #include using namespace std; #define MAX 100 struct no{ int layer; vector next; }node[MAX]; int n,m; int laycnt[MAX]; int inq[MAX]; int maxlay=0; void bfs(){ que原创 2015-01-30 21:21:33 · 253 阅读 · 0 评论 -
1021. Deepest Root (25)
点击打开链接 先用并查集存。且图中只存单边 然后判断利用并查集判断连通分量的个数 如果是连通图,利用并查集补充为无向图,再次bfs得最大深度 但是第一个点竟然没过!!!!! #include #include #include #include #define MAX 10010 #include using namespace std; //并查集 int tr原创 2015-01-31 16:45:21 · 173 阅读 · 0 评论 -
1079. Total Sales of Supply Chain (25)
点击打开链接 数据较大,只能用bfs #include #include #include #include using namespace std; #define MAX 100010 int n; double p,r; struct no{ int layer; vector next; int total; }node[MAX]; double ans=原创 2015-01-31 09:16:12 · 766 阅读 · 0 评论 -
1053. Path of Equal Weight (30)
点击打开链接 注意: 1.对于树的存储和二叉树类似,不同之处在与存储其孩子时用vector struct no{ int data; int wei; //用vector表示其孩子 vector next; }node[MAX]; 2.要求按照权值的从大到小输出 方法1:用set记录所有路径,倒着进行输出 但该方法不可行,虽然set可以排原创 2015-01-30 16:36:22 · 240 阅读 · 0 评论 -
树的基本操作,静态法
树的基本操作 1.定义 lchid和rchild存放的是在tree的序号,不是data值 struct node{ int data; int lchild; int rchild; }tree[MAX]; 2.新建节点 -1表示没有该节点,代替NULL int index=0; int newNode(){ tree[index].lchid=-1; t原创 2015-01-30 09:57:35 · 240 阅读 · 0 评论 -
1086. Tree Traversals Again (25)
点击打开链接 #include #include using namespace std; #define MAX 40 struct node{ int data; int lchild; int rchild; }tree[MAX]; struct aa{ int ac; int da; }act[2*MAX]; int n; int index=0; int原创 2015-01-30 11:45:06 · 330 阅读 · 0 评论 -
1056. Mice and Rice (25)
点击打开链接 终于过了!!! 注意 1.题意首先没读懂,这题后面给的order是其id,意思是order中下标是顺序,内容是id 2.我的思路是建立一个胜者树,不断更新rank,因此就是要记录每次进入下一层的id, 而不是结构体本身,因为这样才能修改结构体中的rank 3.对于最后的输出,要记录下每一层的个数用lay[],然后按照个数更新rank 感觉更新rank的过程太复杂了,应该原创 2015-02-07 16:31:38 · 238 阅读 · 0 评论