02 2016 档案

【ZOJ】3609 Modular Inverse
摘要:1. 题目描述求乘法逆元。2. 基本思路利用扩展gcd求逆元,模板题目。3. 代码 1 /* 3609 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <que 阅读全文

posted @ 2016-02-29 12:41 Bombe 阅读(196) 评论(0) 推荐(0) 编辑

【TopCoder】SRM 680 DIV 2
摘要:1. BearPair之bigDistance1.1 题目概述在 <= 50的字符串中找位置i,j 满足(1) s[i] != s[j];(2) abs(i-j)尽可能大。若不存在返回-1, 否则返回最大值。1.2 基本思路没什么好说的,串长这么短 O(n^2)直接A了。1.3 代码 1 class 阅读全文

posted @ 2016-02-28 23:01 Bombe 阅读(188) 评论(0) 推荐(0) 编辑

【HDOJ】4305 Lightning
摘要:1. 题目描述当一个结点lightning后,可以向其周围距离小于等于R的结点传播lightning。然后以该结点为中心继续传播。以此类推,问最终形成的树形结构有多少个。2. 基本思路生成树级数模板题目。Matrix-Tree定理(Kirchhoff矩阵-树定理):1) G的度数矩阵D[G]是一个n 阅读全文

posted @ 2016-02-28 19:24 Bombe 阅读(154) 评论(0) 推荐(0) 编辑

【HDOJ】4373 Mysterious For
摘要:1. 题目描述有两种不同类型的循环,并给出一个由1、2组成的序列,表示嵌套的循环类型。问这样组着的循环一共需要多少次循环?并将结果模364875103。2.基本思路显然,每当遇到一个类型1的序列,即可以判定12...2的嵌套循环共多少次,而1类型的循环次数为常亮。因此,将原序列从1分开,并将每个子序 阅读全文

posted @ 2016-02-21 15:01 Bombe 阅读(175) 评论(0) 推荐(0) 编辑

【HDOJ】1667 The Rotation Game
摘要:1. 题目描述有个#字型的条带,可以从横线或竖线进行循环移动,求通过各种移动最终使中心的8个字符全等的长度最短并相同长度字典序最小的操作序列。2. 基本思路24个数据,8种移动方式,数据量很小了,所以基本怎么玩儿都可以。需要注意的是因为横线竖线间有交点,所以每个条带的数据可能都是变化的。采用IDA* 阅读全文

posted @ 2016-02-20 11:36 Bombe 阅读(210) 评论(0) 推荐(0) 编辑

【HDOJ】4374 One hundred layer
摘要:线性DP,使用单调队列优化。 1 /* 4374 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #inc 阅读全文

posted @ 2016-02-19 22:16 Bombe 阅读(199) 评论(0) 推荐(0) 编辑

【HDOJ】4363 Draw and paint
摘要:看题解解的。将着色方案映射为40*40*5*5*5*5*2个状态,40*40表示n*m,5*5*5*5表示上下左右相邻块的颜色,0表示未着色。2表示横切或者竖切。基本思路是记忆化搜索然后去重,关键点是可能未切前当前块已经着色了。 1 /* 4363 */ 2 #include <iostream> 阅读全文

posted @ 2016-02-19 15:54 Bombe 阅读(208) 评论(0) 推荐(0) 编辑

【HDOJ】4366 Successor
摘要:基本思路是将树形结构转换为线性结构。然后,所求即为一个区间内大于abi的最大的loy指向的ID。将结点按照abi降序排序,注意abi可能相等。然后,使用线段树单点更新,区间查询可解。 1 /* 4366 */ 2 #include <iostream> 3 #include <sstream> 4 阅读全文

posted @ 2016-02-19 11:36 Bombe 阅读(338) 评论(0) 推荐(0) 编辑

【HDOJ】4358 Boring counting
摘要:基本思路是将树形结构转线性结构,因为查询的是从任意结点到叶子结点的路径。从而将每个查询转换成区间,表示从该结点到叶子结点的路径。离线做,按照右边界升序排序。利用树状数组区间修改。树状数组表示有K个数据的数量,利用pos进行维护。假设现有的sz >= K, 那么需要对区间进行修改。 1 /* 4358 阅读全文

posted @ 2016-02-16 09:11 Bombe 阅读(285) 评论(0) 推荐(0) 编辑

【HDOJ】4351 Digital root
摘要:digital root = n==0 ? 0 : n%9==0 ? 9:n%9;可以简单证明一下n = a0*n^0 + a1*n^1 + ... + ak * n^kn%9 = a0+a1+..+ak然后,数学归纳易知结论是正确的。因此9个状态就够了,表示%9的结果。这里需要特殊处理0, 表示状 阅读全文

posted @ 2016-02-16 01:13 Bombe 阅读(188) 评论(0) 推荐(0) 编辑

【HDOJ】4729 An Easy Problem for Elfness
摘要:其实是求树上的路径间的数据第K大的题目。果断主席树 + LCA。初始流量是这条路径上的最小值。若a<=b,显然直接为s->t建立pipe可以使流量最优;否则,对【0, 10**4】二分得到boundry,使得boundry * n_edge - sum_edge <= k/b, 或者建立s->t,然 阅读全文

posted @ 2016-02-15 15:04 Bombe 阅读(269) 评论(0) 推荐(0) 编辑

【HDOJ】3727 Jewel
摘要:静态区间第K大值。主席树和划分树都可解。 1 /* 3727 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 阅读全文

posted @ 2016-02-15 01:30 Bombe 阅读(121) 评论(0) 推荐(0) 编辑

【HDOJ】4251 The Famous ICPC Team Again
摘要:划分树模板题目,主席树也可解。划分树。 1 /* 4251 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 阅读全文

posted @ 2016-02-15 00:30 Bombe 阅读(129) 评论(0) 推荐(0) 编辑

【HDOJ】4605 Magic Ball Game
摘要:思路1:树状数组+离线处理,对所有的w离散化处理,边dfs边使用树状数组更新左右w的情况。思路2:主席树,边bfs边建树。结点信息存储cnt,然后在线查询。树状数组。 1 /* 4605 */ 2 #include <iostream> 3 #include <sstream> 4 #include 阅读全文

posted @ 2016-02-14 23:34 Bombe 阅读(153) 评论(0) 推荐(0) 编辑

【HDOJ】3473 Minimum Sum
摘要:划分树解。主席树解MLE。 1 /* 3473 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #incl 阅读全文

posted @ 2016-02-14 17:16 Bombe 阅读(166) 评论(0) 推荐(0) 编辑

【POJ】2104 K-th Number
摘要:区间第K大数。主席树可解。 1 /* 2104 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #incl 阅读全文

posted @ 2016-02-13 23:57 Bombe 阅读(164) 评论(0) 推荐(0) 编辑

【HDOJ】4355 Party All the Time
摘要:好久没做过三分的题目了。 1 /* 4355 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #inclu 阅读全文

posted @ 2016-02-13 22:33 Bombe 阅读(176) 评论(0) 推荐(0) 编辑

【HDOJ】4345 Permutation
摘要:即求P1^n1+P2^n2 + ... + Pk^nk <= n,其中Pk为素数的所有可能组合。思路是DP。1~1000的素数就不到200个。dp[i][j]表示上式和不超过且当前最小素数为P[j]的所有可能情况。注意dp[i][0]+1即为所求。 1 /* 4345 */ 2 #include < 阅读全文

posted @ 2016-02-13 22:02 Bombe 阅读(175) 评论(0) 推荐(0) 编辑

【POJ】3468 A Simple Problem with Integers
摘要:这题用线段树轻松解了,重新用树状数组解,关键点是区间更新。公式推导如下:sum[x] = org_sum[x] + delta[1]*x + delta[2]*(x-1) + delta[x]*1 = org_sum[x] + Sigma(delta[1..x]) * (x+1) - Sigma(d 阅读全文

posted @ 2016-02-13 17:54 Bombe 阅读(147) 评论(0) 推荐(0) 编辑

【HDOJ】4348 To the moon
摘要:主席树区间更新,延迟标记。 1 /* 4348 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #incl 阅读全文

posted @ 2016-02-13 17:37 Bombe 阅读(239) 评论(0) 推荐(0) 编辑

【ZOJ】2112 Dynamic Rankings
摘要:树状数组套主席树模板题目。 1 /* 2112 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #incl 阅读全文

posted @ 2016-02-13 13:03 Bombe 阅读(138) 评论(0) 推荐(0) 编辑

【POJ】1811 Prime Test
摘要:rabin_miller判断素数,pollard rho求质因式分解。别人的模板。 1 /* 4344 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <que 阅读全文

posted @ 2016-02-13 00:35 Bombe 阅读(200) 评论(0) 推荐(0) 编辑

【HDOJ】4343 Interval query
摘要:最大不相交集合的数量。思路是dp[i][j]表示已经有i个不相交集合下一个不相交集合的最右边界。离散化后,通过贪心解。 1 /* 4343 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <ma 阅读全文

posted @ 2016-02-13 00:04 Bombe 阅读(233) 评论(0) 推荐(0) 编辑

【HDOJ】4347 The Closest M Points
摘要:居然是KD解。 1 /* 4347 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include <s 阅读全文

posted @ 2016-02-12 15:49 Bombe 阅读(192) 评论(0) 推荐(0) 编辑

【HDOJ】4341 Gold miner
摘要:分组01背包。在一条直线上的点归为一组。 1 /* 4341 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 阅读全文

posted @ 2016-02-12 12:38 Bombe 阅读(144) 评论(0) 推荐(0) 编辑

【HDOJ】4333 Revolving Digits
摘要:扩展KMP基础题目。 1 /* 4333 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include 阅读全文

posted @ 2016-02-11 23:19 Bombe 阅读(195) 评论(0) 推荐(0) 编辑

【HDOJ】4336 Card Collector
摘要:概率DP的题目,一直就不会做这类题目。dp[s]表示状态为s的时候再买多少张牌可以买全,表示的是一个期望值。dp[s] = 1 + P(empty) * dp[s] + P(had) * dp[s] + P(new) * dp[nst]。从而可以解dp[s]。 1 /* 4336 */ 2 #inc 阅读全文

posted @ 2016-02-11 21:26 Bombe 阅读(175) 评论(0) 推荐(0) 编辑

【HDOJ】4328 Cut the cake
摘要:将原问题转化为求完全由1组成的最大子矩阵。挺经典的通过dp将n^3转化为n^2。 1 /* 4328 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queu 阅读全文

posted @ 2016-02-10 22:18 Bombe 阅读(192) 评论(0) 推荐(0) 编辑

【HDOJ】4322 Candy
摘要:状态DP显然可以解,发现T了,不知道优化后能不能过。然后发现费用流可以解。trick是对need拆解成need/K, need%K两种情况讨论。 1 /* 4312 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 阅读全文

posted @ 2016-02-10 16:17 Bombe 阅读(219) 评论(0) 推荐(0) 编辑

【HDOJ】4317 Unfair Nim
摘要:基本的状态压缩,想明白怎么dp还是挺简单的。显然对n个数字进行状态压缩,dp[i][j]表示第i位状态j表示的位向高位产生了进位。 1 /* 4317 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #inclu 阅读全文

posted @ 2016-02-09 23:09 Bombe 阅读(221) 评论(0) 推荐(0) 编辑

【HDOJ】1914 The Stable Marriage Problem
摘要:稳定婚姻问题,Gale-Shapley算法可解。 1 /* 1914 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <s 阅读全文

posted @ 2016-02-07 00:24 Bombe 阅读(176) 评论(0) 推荐(0) 编辑

【HDOJ】3601 Coach Yehr’s punishment
摘要:RMQ+dp+二分。最好还是离散化一下再处理,通过dp求得每个位置的上一次出现的位置pre数组,从而求得不重复的长度len。然后RMQ可以预处理区间的最大值,pre是个单调非递减数列。每次查询时,二分可以找到超过l的位置。注意这个位置k可能超过r。因此最大值为max(k-l, RMQ(k, r) & 阅读全文

posted @ 2016-02-06 22:17 Bombe 阅读(241) 评论(0) 推荐(0) 编辑

【HDOJ】4601 Letter Tree
摘要:挺有意思的一道题,思路肯定是将图转化为Trie树,这样可以求得字典序。然后,按照trie的层次求解。一直wa的原因在于将树转化为线性数据结构时要从原树遍历,从trie遍历就会wa。不同结点可能映射为trie上的同一结点,如1->2 (a) 1->3(a) 2->4(b), 这是trie的结构是RT- 阅读全文

posted @ 2016-02-06 15:56 Bombe 阅读(180) 评论(0) 推荐(0) 编辑

【HDOJ】3686 Traffic Real Time Query System
摘要:这题做了几个小时,基本思路肯定是求两点路径中的割点数目,思路是tarjan缩点,然后以割点和连通块作为新节点见图。转化为lca求解。结合点——双连通分量与LCA。 1 /* 3686 */ 2 #include <iostream> 3 #include <sstream> 4 #include < 阅读全文

posted @ 2016-02-05 22:34 Bombe 阅读(404) 评论(0) 推荐(0) 编辑

【HDOJ】5296 Annoying problem
摘要:LCA+RMQ。挺不错的一道题目。 思路是如何通过LCA维护费用。当加入新的点u是,费用增量为dis[u]-dis[lca(u, lower_u)] - dis[lca(u, greater_u)] + dis[lca(lower_u, greater_u)]。若beg[u]大于当前最大值或小于最小 阅读全文

posted @ 2016-02-05 12:11 Bombe 阅读(313) 评论(0) 推荐(0) 编辑

【HDOJ】3553 Just a String
摘要:后缀数组加二分可解。 1 /* 3553 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include 阅读全文

posted @ 2016-02-05 00:55 Bombe 阅读(149) 评论(0) 推荐(0) 编辑

【HDOJ】4426 Palindromic Substring
摘要:综合性很强的一道题目,结合manacher,后缀数组,哈希,RMQ,二分可解。基本思路是通过manacher可以找到所有可能的回文串,哈希去重,后缀数组二分找数目。最后暴力求解。需要注意kth需要为__int64。 1 /* 4426 */ 2 #include <iostream> 3 #incl 阅读全文

posted @ 2016-02-04 23:13 Bombe 阅读(303) 评论(0) 推荐(0) 编辑

【HDOJ】4029 Distinct Sub-matrix
摘要:思路是枚举矩阵列数,然后将字符矩阵转换成字符串,通过字符数组求不同子串数目。最后,减去不成立的情况。使用特殊字符分割可能的组合。 1 /* 4029 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #includ 阅读全文

posted @ 2016-02-04 12:29 Bombe 阅读(196) 评论(0) 推荐(0) 编辑

【HDOJ】3948 The Number of Palindromes
摘要:后缀数组求不重复回文子串数目。注意dp数组。 1 /* 3948 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set 阅读全文

posted @ 2016-02-04 00:22 Bombe 阅读(259) 评论(0) 推荐(0) 编辑

【HDOJ】4691 Front compression
摘要:后缀数组基础题目,dc3解。 1 /* 4691 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #inc 阅读全文

posted @ 2016-02-03 22:24 Bombe 阅读(210) 评论(0) 推荐(0) 编辑

【POJ】3294 Life Forms
摘要:后缀数组。 1 /* 3294 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include <sta 阅读全文

posted @ 2016-02-03 21:20 Bombe 阅读(170) 评论(0) 推荐(0) 编辑

【POJ】3415 Common Substrings
摘要:后缀数组可解。使用单调栈优化。 1 /* 3415 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #in 阅读全文

posted @ 2016-02-03 16:06 Bombe 阅读(356) 评论(0) 推荐(0) 编辑

【HDOJ】2459 Maximum repetition substring
摘要:后缀数组+RMQ。 1 /* 2459 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include 阅读全文

posted @ 2016-02-03 12:42 Bombe 阅读(172) 评论(0) 推荐(0) 编辑

【HDOJ】2890 Longest Repeated subsequence
摘要:后缀数组的应用。和男人八题那个后缀数组差不多。 1 /* 2890 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <se 阅读全文

posted @ 2016-02-03 01:22 Bombe 阅读(351) 评论(0) 推荐(0) 编辑

【POJ】1743 Musical Theme
摘要:后缀数组基础题目。倍增法解。 1 /* 1743 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #inc 阅读全文

posted @ 2016-02-02 22:23 Bombe 阅读(166) 评论(0) 推荐(0) 编辑

【HDOJ】2388 Playground Hideout
摘要:优先级队列直接AC。 1 /* 2388 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include 阅读全文

posted @ 2016-02-02 11:12 Bombe 阅读(187) 评论(0) 推荐(0) 编辑

【HDOJ】4261 Estimation
摘要:挺不错的一道题,基本思路是dp。关键点是如何求区间内的Sigma|A_i-B_i|。线段树做TLE了,优先队列可以过。 1 /* 4261 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <ma 阅读全文

posted @ 2016-02-01 18:39 Bombe 阅读(273) 评论(0) 推荐(0) 编辑

【HDOJ】4370 0 or 1
摘要:挺有意思的题目。注意等式的条件。等式1实际表示点1的出度为1,等式2实际表示点2的入度为1,等式表示其它点为中间点,入度和出度相等。很容易转换成一条最短路。spfa直接可求,C即为邻接矩阵。同时,可能存在1点出发,最终回到1点的环,从n点出发,最终回到n点的环。 1 /* 4370 */ 2 #in 阅读全文

posted @ 2016-02-01 00:30 Bombe 阅读(140) 评论(0) 推荐(0) 编辑

导航

点击右上角即可分享
微信分享提示