HDU 6115 Factory LCA,暴力】的更多相关文章

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6115 题意:中文题面 分析:直接维护LCA,然后暴力枚举集合维护答案即可. #include <bits/stdc++.h> using namespace std; const int maxn = 200010; const int inf = 0x3f3f3f3f; struct edge{ int to,len,next; }E[maxn*2]; vector<int>G[ma…
Factory Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 367    Accepted Submission(s): 124 Problem Description 我们将A省简化为由N个城市组成,某些城市之间存在双向道路,而且A省的交通有一个特点就是任意两个城市之间都能通过道路相互到达,且在不重复经过城市的情况下任意两个…
题目描述 给定一大小为n的有点权树,每次询问一对点(u,v),问是否能在u到v的简单路径上取三个点权,以这三个权值为边长构成一个三角形.同时还支持单点修改. 输入 第一行两个整数n.q表示树的点数和操作数 第二行n个整数表示n个点的点权 以下n-1行,每行2个整数a.b,表示a是b的父亲(以1为根的情况下) 以下q行,每行3个整数t.a.b 若t=0,则询问(a,b) 若t=1,则将点a的点权修改为b 输出 对每个询问输出一行表示答案,“Y”表示有解,“N”表示无解. 样例输入 5 5 1 2…
Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 5394    Accepted Submission(s): 2422 Problem Description John is a manager of a CPU chip factory, the factory produces lots of chi…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4547 思路:这题的本质还是LCA问题,但是需要注意的地方有: 1.如果Q中u,v的lca为u,那么只需一步u->...->v. 2.如果Q中u,v的lca为v,那么需abs(dist[u]  - dist[v])步. 3.否则以上情况都不满足,那么需abs(dist[v] - dist[lca(u, v)])+1步. #include <iostream> #include <c…
Largest Point Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5461 Description Given the sequence A with n integers t1,t2,⋯,tn. Given the integral coefficients a and b. The fact that select two elements ti and tj…
昨天写了HDU 3966 ,本来这道题是很好解得,结果我想用离线LCA 耍一把,结果发现离线LCA 没理解透,错了好多遍,终得AC ,这题比起 HDU 3966要简单,因为他不用动态查询.但是我还是错了好多遍  T^T... http://acm.split.hdu.edu.cn/showproblem.php?pid=5044 不多说了  思想不是很清楚的可以看一看我的上一篇博文 HDU 3966 直接贴代码 #include<iostream> #include<stdio.h>…
题目大意:求树上任意两点距离. 思路: dis[i]表示i到根的距离(手动选根),则u.v的距离=dis[u]+dis[v]-2*dis[lca(u,v)]. lca:u~v的dfs序列区间里,深度最小的节点即为u.v的lca(最近公共祖先),RMQ把它找到.   难点: 何为dfs序: 就是树上dfs依次遍历的节点编号的序列.它的特点是回溯时会[再次]经过非叶节点,非叶节点在dfs序中出现多次,且dfs序列个数>节点个数. 为什么要用dfs序: 因为u.v的lca只出现在u.v的dfs序间.比…
Teacher Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 Description Teacher BoBo is a geography teacher in the school.One day in his class,he marked N points in the map,the i-th point is at (Xi,Yi).He wonders,whether there is a tetrad (A,B,C,…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目: 题意: 对于给定的n个数,求出三个下标不同的数使得(si+sj)^sk最大. 思路: 由于时间给了9s,所以可以暴力过.不过还可以用01字典树艹过去,不过注意字典树里面存si查询(sj+sk),不要存(si+sj)查询sk,不然会T. 暴力代码实现如下: #include <set> #include <map> #include <deque> #incl…