摘要: http://poj.org/problem?id=1330题意:给n个点,n-1条边,一棵树,求每个询问的LCA;思路:rmq求LCA。。。。http://dongxicheng.org/structure/lca-rmq/View Code #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <queue>#include <stack>#include < 阅读全文
posted @ 2012-09-19 22:08 E_star 阅读(243) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=4291题意:...思路:首先暴力求出最外层模100000007的循环节MOD2,然后求出模MOD2的循环节MOD1.求出循环节后用类似与斐波那契数列举证优化的方法求解将时间复杂度由O(N)降到O(logN*2^3);ps:注意这里我们虽然求(n - 1)次幂就能得到{fn,fn-1}了,但是对于当n等于0时就要特殊判断,单纯的一个求幂判断完毕也就罢了,但是当多次求幂时,里面套着也会出现0也需要判断。比较麻烦您容易忽略。所以我们可以求到a^n次方去a.mat[0][1] = a.mat[1][0]。 当计算n- 阅读全文
posted @ 2012-09-19 19:17 E_star 阅读(241) 评论(0) 推荐(0) 编辑
摘要: 数据结构struct Mat{ ll mat[3][3]; void init(){ for (int i = 0; i < 2; ++i){ for (int j = 0; j < 2; ++j){ mat[i][j] = ; } } mat[1][1] = 0; }}; 乘法Mat operator * (Mat a,Mat b){ Mat c; int i,j,k; CL(c.mat,0); for (i = 0; i < 2; ... 阅读全文
posted @ 2012-09-19 10:42 E_star 阅读(371) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3070思路:这里n很大单纯的递推是O(N)会超时,所以要用矩阵快速幂优化;f(n) 1 1 f(1) = 的n-1次方 *f(n-1) 1 0 f(0)View Code #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <queue>#include <stack>#include <set>#in 阅读全文
posted @ 2012-09-19 10:03 E_star 阅读(330) 评论(0) 推荐(0) 编辑