depth

洛谷P3884《[JLOI2009]二叉树问题》

霸气de小男生 提交于 2019-12-02 12:29:31
原创建时间:2018-08-08 16:31:55 不用倍增的 almost裸的LCA 题目描述 如下图所示的一棵二叉树的深度、宽度及结点间距离分别为: 深度:4 宽度:4(同一层最多结点个数) 结点间距离: ⑧→⑥为8 (3×2+2=8) ⑥→⑦为3 (1×2+1=3) 注:结点间距离的定义:由结点向根方向(上行方向)时的边数×2, 与由根向叶结点方向(下行方向)时的边数之和。 图片来自洛谷 Input / Output 格式 & 样例 输入格式 输入文件第一行为一个整数n(1≤n≤100),表示二叉树结点个数。接下来的n-1行,表示从结点x到结点y(约定根结点为1),最后一行两个整数u、v,表示求从结点u到结点v的距离。 输出格式: 三个数,每个数占一行,依次表示给定二叉树的深度、宽度及结点u到结点v间距离。 输入输出样例 输入样例: 10 1 2 1 3 2 4 2 5 3 6 3 7 5 8 5 9 6 10 8 6 输出样例: 4 4 8 解题思路 树的深度可以取 \(max\) { \(depth[i]\) } 树的宽度可以在取深度的时候拿一个桶记录下来,再循环取一遍 \(max\) 两点之间的距离可以先求 \(LCA\) ,再用一个公式算出来 \[distance = (depth[u] - depth[lca]) \times 2 + depth[v] -

c++ - FreeImage+OpenCV - 16bit image get distorted

拥有回忆 提交于 2019-12-02 10:08:09
I'm trying to load an image because I have to apply an algorithm on it. If I load an 8 bit-per-channel image there are no problems, but if I load a 16bpc image then it get "ruined". Unfortunatly, since I don't have enough reputation I can't uplad images. Those are the links to them: Either the source and the 8bpc processing result http://postimg.org/image/gc0zf2lp5/ ..result if I process the same image saved as 16bpc http://postimg.org/image/5nnwee7df/ And this is the code: FreeImage_Initialise(); FREE_IMAGE_FORMAT formato = FreeImage_GetFileType(argv[1], 0); FIBITMAP* imagetmp = FreeImage

Convert device pose to camera pose

我的未来我决定 提交于 2019-12-02 09:46:00
I'm using the camera intrinsic (fx, fy, cx, cy, width, hight) to store a depth image of TangoXyzIjData.xyz buffer. Therefore I calculate for each point of xyz the corresponding image point and store its z value x' = (fx * x) / z + cx y' = (fy * y) / z + cy depthImage[x'][y'] = z Now I would like to store the corresponding pose data as well. I'm using the timestamp of TangoXyzIjData.timestamp and the following function getPoseAtTime(double timestamp, TangoCoordinateFramePair framePair) with framepair new TangoCoordinateFramePair(TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE, TangoPoseData

二叉树的最大深度

折月煮酒 提交于 2019-12-02 06:13:27
给定一个二叉树,找出其最大深度。 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。 递归: public int maxDepth ( TreeNode root ) { if ( root == null ) { return 0 ; } else { int left_height = maxDepth ( root . left ) ; int right_height = maxDepth ( root . right ) ; return Math . max ( left_height , right_height ) + 1 ; } } 迭代: public int maxDepth ( TreeNode root ) { Queue < Pair < TreeNode , Integer > > stack = new LinkedList < > ( ) ; if ( root != null ) { stack . add ( new Pair ( root , 1 ) ) ; } int depth = 0 ; while ( ! stack . isEmpty ( ) ) { Pair < TreeNode , Integer > current = stack . poll ( ) ; root = current . getKey ( ) ;

Tango raw depth data - update? [closed]

泄露秘密 提交于 2019-12-02 03:05:28
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago . I bought the lenovo phab 2 pro supporting the tango project from google. Using this setup, it it possible to obtain depth data in form of a pointcloud. But this is not what I need. I would prefer to obtain data in a more raw format like possible to be obtained by the Kinect, where each pixel of the

Tango raw depth data - update? [closed]

痴心易碎 提交于 2019-12-02 01:57:14
I bought the lenovo phab 2 pro supporting the tango project from google. Using this setup, it it possible to obtain depth data in form of a pointcloud. But this is not what I need. I would prefer to obtain data in a more raw format like possible to be obtained by the Kinect, where each pixel of the imageplane is assigned a depth value. My question therefore: Is the depth data of the phab2 (or any tango device) possible to be obtained in such a raw format where each pixel is assigned a depth value? My research lead me to countless unsolved cases (typing tango raw data or similar in google,

洛谷 P5019 铺设道路

安稳与你 提交于 2019-12-02 00:34:46
赛道修建 题面查看 其实看到题目的第一想法其实是二分,每一次找一个minx,再记录它的pos,对于(l,pos-1)和(pos+1,r)继续做,然后一看数据范围, \(1≤n≤100000\) ,立刻就否决了. 其实在考场上说不定我就打70分了 然后我就开始对于数据进行模拟, 突然灵光一闪 ,发现如果对于一个坑 x , \(\forall depth_x+1>depth_x\) ,我们会将 \([x,x+1]\) 区间内的数全部减去 \(d_x\) ,那么这个 x 就是不必要的. 于是就有了如下的贪心策略 \[ \sum_{\forall depth_x>depth_{x-1}} depth_x-depth_{x-1} \] 然后问题就迎刃而解了,附上代码 #include <iostream> using namespace std; const int maxn = 100005; long long n, a[maxn]; long long ans; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i];//a[i]即depth[i] for (int i = 2; i <= n; i++) if (a[i] > a[i - 1]) ans += a[i] - a[i - 1]; cout <<

遍历目录的正确方法

若如初见. 提交于 2019-12-01 13:03:47
/** * 遍历目录 * @staticvar int $depth * @staticvar array $path * @param type $dir * @param type $clear 是否销毁静态变量 * @return string|boolean */ public function _scan($dir, $clear = false) { static $depth = 0; static $path = array(); // 无限遍历 // if ($depth >= 10000) { // return false; // } if($clear) { $path = null; static $path = array(); } $dirArr = scandir($dir); foreach ($dirArr as $v) { if (substr($v, 0, 1) != '.') {//去掉隐藏目录或文件 $dirname = $dir . DS . $v; //子文件夹的目录地址 if (is_dir($dirname)) { $depth++; $this->_scan($dirname); } else { $path[] = $dirname; } } } return $path; }    来源: https://www

HDU 2586

别说谁变了你拦得住时间么 提交于 2019-12-01 13:01:40
题意: 一道很裸的LCA题 以一个点建树,两点间最短的距离可以转化为求两近公共祖先,最短距离,depth[x]-depth[l]+depth[y]-depth[l] 在dfs求得每个点到顶点距离 #include<iostream> #include<cstring> #include<algorithm> #include<vector> using namespace std; const int maxn=4e4+5; const int maxbit=15; struct edge { int to; int val; }; int father[maxn][maxbit]; int depth[maxn]; int dis[maxn];vector<edge>G[maxn]; int lg[maxn]; void dfs(int nowp,int fa) { depth[nowp]=depth[fa]+1; father[nowp][0]=fa; for(int j=1;j<=lg[depth[nowp]];j++) father[nowp][j]=father[father[nowp][j-1]][j-1]; for(int i=0;i<G[nowp].size();i++) { edge e=G[nowp][i]; if(e.to!=fa) { dis[e.to]

LCA【模板】

故事扮演 提交于 2019-12-01 09:48:36
#include<iostream> #include<cstdio> using namespace std; struct yyy{ int t, nex; }e[2*500001]; int depth[500001],fa[500001][22],lg[500001],head[500001]; int tot; void add(int x,int y) //邻接表存树 { e[++tot].t=y; e[tot].nex=head[x]; head[x]=tot; } void dfs(int f,int fath) { depth[f]=depth[fath]+1; fa[f][0]=fath; for(int i=1;(1<<i)<=depth[f];i++) fa[f][i]=fa[fa[f][i-1]][i-1]; for(int i=head[f];i;i=e[i].nex) if(e[i].t!=fath) dfs(e[i].t,f); } int lca(int x,int y) { if(depth[x]<depth[y]) swap(x,y); while(depth[x]>depth[y]) x=fa[x][lg[depth[x]-depth[y]]-1]; if(x==y) return x; for(int k=lg[depth[x]]-1;k>