
pat-a-树
文章平均质量分 66
要认认真真
这个作者很懒,什么都没留下…
展开
-
1020. Tree Traversals (25)
点击打开链接#include #include using namespace std;#define MAX 40struct 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 · 200 阅读 · 0 评论 -
1064. Complete Binary Search Tree (30)
点击打开链接由完全二叉树和二叉搜索树构造出二叉树,然后层次遍历先画出完全二叉树的模样,即确定左右孩子,因为都存储的是序号,左孩子为2*i,右孩子为2*i+1由于bst中序遍历为有序的,因此中序遍历时确定data值#include #include using namespace std;#define MAX 10010struct no{ int da原创 2015-02-01 17:25:14 · 225 阅读 · 0 评论 -
1090. Highest Price in Supply Chain (25)
点击打开链接与1079类似数据大,用bfs#include #include #include #include using namespace std;#define MAX 100010struct no{ int layer; vector next;}node[MAX];int n;double p,r;int root;void bfs(原创 2015-01-31 09:44:29 · 348 阅读 · 0 评论 -
1004. Counting Leaves (30)
点击打开链接#include #include #include using namespace std;#define MAX 100struct 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 · 280 阅读 · 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 · 201 阅读 · 0 评论 -
1079. Total Sales of Supply Chain (25)
点击打开链接数据较大,只能用bfs#include #include #include #include using namespace std;#define MAX 100010int n;double p,r;struct no{ int layer; vector next; int total;}node[MAX];double ans=原创 2015-01-31 09:16:12 · 810 阅读 · 0 评论 -
1053. Path of Equal Weight (30)
点击打开链接注意:1.对于树的存储和二叉树类似,不同之处在与存储其孩子时用vectorstruct no{ int data; int wei; //用vector表示其孩子 vector next;}node[MAX];2.要求按照权值的从大到小输出方法1:用set记录所有路径,倒着进行输出但该方法不可行,虽然set可以排原创 2015-01-30 16:36:22 · 268 阅读 · 0 评论 -
树的基本操作,静态法
树的基本操作1.定义lchid和rchild存放的是在tree的序号,不是data值struct node{ int data; int lchild; int rchild;}tree[MAX];2.新建节点-1表示没有该节点,代替NULLint index=0;int newNode(){ tree[index].lchid=-1; t原创 2015-01-30 09:57:35 · 274 阅读 · 0 评论 -
1086. Tree Traversals Again (25)
点击打开链接#include #include using namespace std;#define MAX 40struct 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 · 357 阅读 · 0 评论 -
1056. Mice and Rice (25)
点击打开链接终于过了!!!注意1.题意首先没读懂,这题后面给的order是其id,意思是order中下标是顺序,内容是id2.我的思路是建立一个胜者树,不断更新rank,因此就是要记录每次进入下一层的id,而不是结构体本身,因为这样才能修改结构体中的rank3.对于最后的输出,要记录下每一层的个数用lay[],然后按照个数更新rank感觉更新rank的过程太复杂了,应该原创 2015-02-07 16:31:38 · 278 阅读 · 0 评论