返回顶部
摘要: #include<cstdio>#include<iostream>#include<iterator>#include<algorithm>#include<set>#include<vector>#include<cmath>#include<cstring>using namespace st 阅读全文
posted @ 2021-01-22 09:16 tianyudizhua 阅读(55) 评论(0) 推荐(0) 编辑
摘要: [Warning] pointer to a function used in arithmetic [-Wpointer-arith] 关于这个warning,直译是将指向函数的指针运用于计算一开始我不明白,后来经仔细检查后发现我定义的一个函数,需要的变量是三个int,但我最后在使用函数时,本来应 阅读全文
posted @ 2020-08-31 19:26 tianyudizhua 阅读(1506) 评论(0) 推荐(0) 编辑
摘要: #include<iostream> using namespace std; struct node { int v,height; node*lchild; node*rchild; int data; }; int x; node* newNode(int v) { node*Node =ne 阅读全文
posted @ 2020-08-12 20:48 tianyudizhua 阅读(173) 评论(0) 推荐(0) 编辑
摘要: root->right漏写置空了 for(int i=0;i<res.size()-1;i++) { int data=res.front(); res.pop(); printf("%d ",data); } 每弹一次队列size就会减少,这样就弹不完 阅读全文
posted @ 2020-08-12 04:11 tianyudizhua 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 记T为一棵二叉树,树中共有n个节点。 定义根节点的深度为0,其余节点的深度为其父节点的深度加1。T的高度定义为其叶节点深度的最大值。 定义树中任意两点a和b之间的距离为其间最短简单路径的长度。T的直径定义为T中所有点对间距离的最大值。 输入一棵二叉树T,请计算它的高度和直径。 思路:高度直接递归,南 阅读全文
posted @ 2020-08-12 02:47 tianyudizhua 阅读(319) 评论(0) 推荐(0) 编辑
摘要: #include<cstdio>#include<iostream>#include<stdlib.h>#include<queue>using namespace std;typedef struct BTree{ int data; BTree *lchild; BTree *rchild; } 阅读全文
posted @ 2020-08-11 21:50 tianyudizhua 阅读(126) 评论(0) 推荐(0) 编辑
摘要: #include<cstdio> #include<vector> using namespace std; const int maxn=20; int n,k,x,maxSumSqu=-1,A[maxn]; vector<int>temp,ans; void DFS(int index,int 阅读全文
posted @ 2020-08-11 20:37 tianyudizhua 阅读(204) 评论(0) 推荐(0) 编辑
摘要: #include<cstdio> const int maxn=30; int n,V,maxValue=0; int w[maxn],c[maxn]; void DFS(int index,int sumW,int sumC) { if(index==n) { return; } DFS(inde 阅读全文
posted @ 2020-08-11 20:17 tianyudizhua 阅读(89) 评论(0) 推荐(0) 编辑
摘要: #include<cstdio> const int maxn=30; int n,V,maxValue=0; int w[maxn],c[maxn]; void DFS(int index,int sumW,int sumC) { if(index==n) { if(sumW<=V&&sumC>m 阅读全文
posted @ 2020-08-11 20:15 tianyudizhua 阅读(88) 评论(0) 推荐(0) 编辑
摘要: void BFS(int s) { queue<int>q; q.push(s); while(!q.empty()) { //取出队首元素top //访问队首元素top //将队首元素出队 //将top的下一次结点中未曾入队的结点全部入队,标记层号为now的层号+1并设置为已入队 } } 阅读全文
posted @ 2020-08-11 20:00 tianyudizhua 阅读(107) 评论(0) 推荐(0) 编辑