poj 1330(RMQ&LCA入门题)】的更多相关文章

传送门:Problem 1330 https://www.cnblogs.com/violet-acmer/p/9686774.html 参考资料: http://dongxicheng.org/structure/lca-rmq/ 挑战程序设计竞赛(第二版) 变量解释: 对有根树进行DFS,将遍历到的节点按照顺序记下,我们将得到一个长度为2N-1的序列,称之为欧拉序列. total : 记录dfs遍历过程中回溯的节点编号,其实就是从0->2N-1. vs[ ] : 记录DFS访问的顺序,也就是…
链接:http://poj.org/problem?id=1330 题意:q次询问求两个点u,v的LCA 思路:LCA模板题,首先找一下树的根,然后dfs预处理求LCA(u,v) AC代码: #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<set> #include<string> #include<vector&…
这道题是我对于2-SAT问题的入门题:http://poj.org/problem?id=3207 一篇非常非常非常好的博客,很详细,认真看一遍差不多可以了解个大概:https://blog.csdn.net/JarjingX/article/details/8521690 总结一下我对于 2-SAT 问题的初步见解: 有很多个集合,每个集合里面有若干元素,现给出一些取元素的规则,要你判断是否可行,可行则给出一个可行方案.如果所有集合中,元素个数最多的集合有k个,那么我们就说这是一个k-sat问…
有一个大学的庆典晚会,想邀请一些在大学任职的人来參加,每一个人有自己的搞笑值,可是如今遇到一个问题就是假设两个人之间有直接的上下级关系,那么他们中仅仅能有一个来參加,求请来一部分人之后,搞笑值的最大是多少. 树形DP入门题. DP部分: dp[i][0]表示职员i不来參加party,以i为根的子树的最大搞笑值, dp[i][1]表示职员i来參加party.以i为根的子树的最大搞笑值. 转移方程: dp[cur][1]+=dp[next][0]; dp[cur][0]+=Max(dp[next][…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2586 题目: How far away ? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 21500    Accepted Submission(s): 8471 Problem Description There are n house…
http://poj.org/problem?id=1330 题意:给出一个图,求两个点的最近公共祖先. sl :水题,贴个模板试试代码.本来是再敲HDU4757的中间发现要用LCA,  操蛋只好用这个题目试试自己写的对不对. 下面是个倍增的写法,挺实用的. 好了,继续... ;  ][MAX],dep[MAX];       G[     G[to].push_back( }      dep[u]=d; parent[][u]=pre;     ;i<G[u].size();i++) {  …
Nearest Common Ancestors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23795   Accepted: 12386 Description A rooted tree is a well-known data structure in computer science and engineering. An example is shown below: In the figure, each…
题意:给你一棵树,求两个点的最近公共祖先. 思路:因为只有一组询问,直接数组模拟好了. (写得比较乱) 原题请戳这里 #include <cstdio> #include <bitset> #include <cstring> #include <algorithm> using namespace std; int first[10005],v[10005],next[10005]; int main() { int cas; scanf("%d…
POJ 3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, }; 它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线. Input 一个5 × 5的二维数组,表示一个迷宫.数据保证有唯一解. Output 左上角到右下角的最短路径,格式…
Nearest Common Ancestors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 34657   Accepted: 17585 Description A rooted tree is a well-known data structure in computer science and engineering. An example is shown below:  In the figure, eac…