题目链接:传送门 题目大意:一棵无根树,每个点上有权值,两种操作,0 x y询问x~y路径上权值和 1 x y将 节点 x 权值变为y.对于询问操作输出答案. 题目思路:树链剖分 #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <cstring> #include <st…
Aladdin and the Return Journey Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on LightOJ. Original ID: 134864-bit integer IO format: %lld      Java class name: Main Finally the Great Magical Lamp was in Aladdin's hand. Now he wa…
Finally the Great Magical Lamp was in Aladdin's hand. Now he wanted to return home. But he didn't want to take any help from the Genie because he thought that it might be another adventure for him. All he remembered was the paths he had taken to reac…
题目 Link 分析 典型的树链剖分题, 树链剖分学习资料 Code #include <bits/stdc++.h> using namespace std; const int maxn = 30000 + 131; struct Edge { int Next; int To; }edge[maxn<<1]; int Head[maxn], tot, n; ///以下是重链数据定义 int top[maxn]; //重链的顶点 int deep[maxn]; //树上节点的深…
题意: 就是求a的因数中大于b的有几对 解析: 先把素数打表 运用算术基本定理 求出a的所有因数的个数 然后减去小于b的因数的个数 代码如下: #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include <stac…
题意: 就是哥德巴赫猜想...任意一个偶数 都可以分解成两个(就是一对啦)质数的加和 输入一个偶数求有几对.. 解析: 首先! 素数打表..因为 质数 + 质数 = 偶数 所以 偶数 - 质数 = 质数 ... 我真是蠢啊 还有  vis要用bool类型的!!!!  int会直接爆 代码如下: #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #includ…
Lambda表达式和表达式树 先放一张委托转换的进化图 看一看到lambda简化了委托的使用. lambda可以隐式的转换成委托或者表达式树.转换成委托的话如下面的代码: Func<string, int> getLength = s => s.Length; 转换成表达式树的话是下面的代码: Expression<Func<string, int>> getLength = s => s.Length; 委托方面的东西前面都做了详细的介绍.我们主要学习表达…
题意: 就是求1-n中有多少对i 和 j 的最小公倍数为n  (i <= j) 解析: 而这题,我们假设( a , b ) = n ,那么: n=pk11pk22⋯pkss, a=pd11pd22⋯pdss, b=pe11pe22⋯pess, 可以确定max(ei,di)=ki,      关于这点 可以自己反证一下 那么ki的组成就是ei与di中一个等于ki, 另一个任取[0,ki-1]中的一个数, 那么就有 2ki 种方案, 由于 ei=di=ki 只有一种,(两种都为ki) 所以第i位方案…
题意: 求前n项的n/i  的和 只取整数部分 暴力肯定超时...然后 ...现在的人真聪明...我真蠢 觉得还是别人的题意比较清晰 比如n=100的话,i=4时n/i等于25,i=5时n/i等于20,于是在大于20到小于等于25内的5个数字j都有n/j等于4,然后ans+=4*5 所以我们可以在小于等于根号n的范围内枚举i,ans+=n/i,然后ans+=(n/(i)-n/(i+1))*i,这样分段加起来 但是又重复的部分.. 即 令m = sqrt(n), 如果n / m == m 则n /…
题意:1~100的格子,有n个传送阵,一个把进入i的人瞬间传送到tp[i](可能传送到前面,也可能是后面),已知传送阵终点不会有另一个传送阵,1和100都不会有传送阵.每次走都需要掷一次骰子(1~6且可能性一样),掷多少走多少,目的地超出100重掷,问你走到100所需掷骰子的期望. 思路:概率DP肯定的,但是会往前传送就很难直接算.用DP[i]代表从i走到100的期望. 那么如果i没有传送阵,则有:DP[i] = 1 / 6 * sum(DP[i + j]) + 1,1<= j <= 6,如果…