depth

LCA倍增

北城以北 提交于 2019-11-29 22:01:25
#include <iostream> #include <cstdio> #include <vector> #include <cstring> using namespace std; const int maxn=5e5+10; int depth[maxn],fa[maxn][22],lg[maxn]; int tot; int head[maxn<<1],e[maxn<<1],nex[maxn<<1]; void add(int x,int y) { e[++tot]=y; nex[tot]=head[x]; head[x]=tot; } void dfs(int cur,int fath) { depth[cur]=depth[fath]+1; fa[cur][0]=fath; for(int i=1; (1<<i)<=depth[cur]; i++) { fa[cur][i]=fa[fa[cur][i-1]][i-1]; } for(int i=head[cur]; i!=-1; i=nex[i]) { if(e[i]==fath) continue; dfs(e[i],cur); } } int lca(int x,int y) { if(depth[x]<depth[y]) swap(x,y); while(depth[x]>depth[y]) x=fa[x]

「LCA」[USACO10HOL]牛的政治Cow Politics

自作多情 提交于 2019-11-29 11:16:35
[USACO10HOL]牛的政治Cow Politics 题目链接: [USACO10HOL]牛的政治Cow Politics 题目大意 给你 \(n\) 个关系,再给你一共有多少个群落,每个关系包含两个内容,在哪个群落以及当前 \(i\) 节点的父亲节点是谁。然后让你求每个群落距离最远的两个点的距离是多大 题目题解 刚开始想的是树的直径,但看了下样例发现都是在一棵树上进行的,搜肯定不怎么好搜,想想其他的办法。然后又想到LCA可以求两点的距离,那么可以考虑用LCA求两点距离,这里我们通过题意理解可以知道,如果选择一个深度最深的点作为其中一个点,那么其定会有一种与其他点的距离方案是我们的答案(简单的贪心),那么我们先确定一点的位置,然后再通过遍历和计算直接计算最大的距离不就OK了吗,然后就... AC了 代码如下 //#define fre yes #include <cstdio> #include <cstring> #include <iostream> const int N = 200005; int head[N << 1], to[N << 1], ver[N << 1]; int maxx[N], color[N], ans[N]; int depth[N], f[N][22], lg[N]; int n, m, root; int tot; void addedge

OpenCv depth estimation from Disparity map

点点圈 提交于 2019-11-29 10:36:39
问题 I'm trying to estimate depth from a stereo pair images with OpenCV. I have disparity map and depth estimation can be obtained as: (Baseline*focal) depth = ------------------ (disparity*SensorSize) I have used Block Matching technique to find the same points in the two rectificated images. OpenCV permits to set some block matching parameter, for example BMState->numberOfDisparities . After block matching process: cvFindStereoCorrespondenceBM( frame1r, frame2r, disp, BMState); cvConvertScale(

110. Balanced Binary Tree

前提是你 提交于 2019-11-28 23:16:28
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Note: A leaf is a node with no children. Example: Given binary tree [3,9,20,null,null,15,7] , 3 / \ 9 20 / \ 15 7 return its depth = 3. /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { public boolean isBalanced(TreeNode root) { if(root == null) return true; int l = depth(root.left); int r = depth(root.right); return

Q matrix for the reprojectImageTo3D function in opencv

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 20:53:52
I am doing a project in opencv to detect obstacle in the path of a blind person using stereo calibration. I have calculated the disparity map correctly. Now to find the distance of obstacle from the camera, I want its 3D coordinates [X,Y,Z] , which I am guessing can be found by reprojectImageTo3D(), but I dont have the Q matrix to use in this function because the Q matrix I am getting from stereoRectify() is coming null probably because I used pre calibrated images. Although I do have the inrinsic and extrinsic parameters of my camera. So my question is that how can I manually create the Q

Calculate surface normals from depth image using neighboring pixels cross product

会有一股神秘感。 提交于 2019-11-28 17:35:19
As the title says I want to calculate the surface normals of a given depth image by using the cross product of neighboring pixels. I would like to use Opencv for that and avoid using PCL however, I do not really understand the procedure, since my knowledge is quite limited in the subject. Therefore, I would be grateful is someone could provide some hints. To mention here that I do not have any other information except the depth image and the corresponding rgb image, so no K camera matrix information. Thus, lets say that we have the following depth image: and I want to find the normal vector at

WebGL drawing 2D image with depth map to achieve pseudo-3D effect

冷暖自知 提交于 2019-11-28 09:33:50
I'm learning WebGL, done that with the help of WebGLFundamentals page, which helped me pretty much to understand how buffers, shaders and all that stuff works. But now I want to achieve a certain effect which I saw here: https://tympanus.net/Tutorials/HeatDistortionEffect/index3.html I know how to make the heat distortion effect, the effect I want to achieve is the DEPTH on the image. This demo has a tutorial but it doesnt really explain how to do it, it says I must have a grayscale map, in which the white parts are the closest ones and the black parts the farest. But I really cant understand

Depth as distance to camera plane in GLSL

丶灬走出姿态 提交于 2019-11-28 07:04:09
I have a pair of GLSL shaders that give me the depth map of the objects in my scene. What I get now is the distance from each pixel to the camera. What I need is to get the distance from the pixel to the camera plane. Let me illustrate with a little drawing * |--* / | / | C-----* C-----* \ | \ | * |--* The 3 asterisks are pixels and the C is the camera. The lines from the asterisks are the "depth". In the first case, I get the distance from the pixel to the camera. In the second, I wish to get the distance from each pixel to the plane. There must be a way to do this by using some projection

Implementing Depth First Search into C# using List and Stack

会有一股神秘感。 提交于 2019-11-28 03:58:39
I want to create a depth first search which I have been somewhat successful in. Here is my code so far (Except my constructor, note the Vertex and Edge classes only contain properties, nothing important to post here): private Stack<Vertex> workerStack = new Stack<Vertex>(); private List<Vertex> vertices = new List<Vertex>(); private List<Edge> edges = new List<Edge>(); private int numberOfVertices; private int numberOfClosedVertices; private int visitNumber = 1; private void StartSearch() { // Make sure to visit all vertices while (numberOfClosedVertices < numberOfVertices && workerStack.Count

LCA

旧时模样 提交于 2019-11-28 03:57:38
1 #include <cstdio> 2 #include <iostream> 3 #include <algorithm> 4 #include <cstring> 5 using namespace std; 6 const int maxn = 1e6 + 5; 7 struct node 8 { 9 int u , v , next; 10 }G[maxn]; 11 int tail , head[maxn]; 12 int n , m , s; 13 int depth[maxn] , father[maxn][25] , lg[maxn]; 14 void add(int u , int v) 15 { 16 tail++; 17 G[tail].u = u , G[tail].v = v , G[tail].next = head[u]; 18 head[u] = tail; 19 } 20 void dfs(int p , int fa) 21 { 22 depth[p] = depth[fa] + 1; 23 father[p][0] = fa; 24 for(int i = 1; (1 << i) <= depth[p]; i++) 25 father[p][i] = father[father[p][i - 1]][i - 1]; 26 for(int i