上一页 1 ··· 6 7 8 9 10 11 12 13 14 下一页
摘要: 并查集的高效之处在于路径压缩和延迟更新。在本题中需要额外维护子树的规模以及当前子树节点到跟的距离两个数组。由于一个新的数必然是两棵树拼接而成,对于子树规模的更新直接相加即可,对于节点到跟的距离:我们让a树的根指向b树的根,同时更新a树根到(a+b)树根(即b树根)的距离为size_of(Tree(b... 阅读全文
posted @ 2015-09-23 19:36 astoninfer 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 此题可以先排序再用rmq递归解决。当然可以用treap。http://poj.org/problem?id=1785 1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxn = 5e4 + 10; 6 s... 阅读全文
posted @ 2015-09-23 16:05 astoninfer 阅读(245) 评论(0) 推荐(0) 编辑
摘要: 设输入矩阵为A,输出矩阵为B,目标矩阵为C(零矩阵)。方便起见,矩阵行列下标均从1开始。考虑A矩阵元素a(i,j),B矩阵中与其相邻的元素 b(i,j),b(i - 1, j),b(i + 1,j),b(i,j - 1),b(i,j + 1) (#)。有c(i,j)= 0 = a(i,j) ^ (∑... 阅读全文
posted @ 2015-09-22 19:45 astoninfer 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 题目意思就不赘述了。这是一个计数问题,一开始考虑如何去重却没有想到可行的办法。原因是只考虑计数连通的方案数是困难的。设n阶图连通的方案数为f(n),不连通的方案数为g(n) = 2^(2, n) - f(n)。不连通的图存在多于1个的连通分量,而每个连通分量是连通的,这是本题的切入点。考虑点1所在的... 阅读全文
posted @ 2015-09-21 22:46 astoninfer 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 可以证明:f(k) = k *(k - 1)/ 2 (1 ≤ k≤ n)是n的完全剩余系当且仅当n = 2 ^ t。http://poj.org/problem?id=3372 阅读全文
posted @ 2015-09-21 18:14 astoninfer 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 给定有序数组a[1...n]的一个置换a[σ(1)...σ(n)], 通过交换数组元素把置换后的数组恢复为有序,定义进行一次交换的代价为两元素之和,试问此过程的最小总代价。实际上一种置换即定义S = {1,...,n}到其自身的一个双射函数f。可以证明必然存在整数k使得f^k = f0 = I。即存... 阅读全文
posted @ 2015-09-20 19:37 astoninfer 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 给你一个正n( i % n -> 2 *i % n ->... -> 01 : 1 -> (i + 1) % n -> (i * 2 + 1) % n ->... -> 1...d - 1 : d - 1 -> (i + d - 1) % n -> (i * 2 + d - 1) % n ->...... 阅读全文
posted @ 2015-09-20 11:48 astoninfer 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 用miller_rabin 和 pollard_rho对大数因式分解,再用dfs寻找答案即可。 http://poj.org/problem?id=2429 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #incl 阅读全文
posted @ 2015-09-17 16:15 astoninfer 阅读(240) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1811 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 typedef __int64 LL; 7 const int times =... 阅读全文
posted @ 2015-09-17 14:25 astoninfer 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 考虑用筛法排除区间内所有合数,对余下的数(素数)更新答案。http://poj.org/problem?id=2689 1 #include 2 #include 3 #include 4 using namespace std; 5 typedef __int64 LL; 6 const i... 阅读全文
posted @ 2015-09-16 14:49 astoninfer 阅读(134) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 12 13 14 下一页