摘要: 可以用后缀数组来做。我说以下ac自动机的做法:加入每个单词,对路径上的所有点累计访问次数。构建fail指针。把每个节点的访问次数累加到它的fail上。具体有代码。。(我写的很挫 - -)/** * Problem:Word * Author:Shun Yao * Time:2013.5.21 * Result:Accepted * Memo:AC-automation */#include <cstring>#include <cstdlib>#include <cstdio>using namespace std;long n, l, r;char s[2 阅读全文
posted @ 2013-05-21 21:27 hsuppr 阅读(322) 评论(0) 推荐(0) 编辑
摘要: 费用流,因为要求全部都是回路, 每个点出入度都为1,拆点分别代表出点和入点,剩下不多说。注意边界可以走 即n->1/** * Problem:Grid * Author:Shun Yao * Time:2013.5.21 * Result:Accepted * Memo:CostFlow */#include <cstring>#include <cstdlib>#include <cstdio>using namespace std;const long dir[2][4] = {{0, 0, -1, 1}, {-1, 1, 0, 0}}, Maxt 阅读全文
posted @ 2013-05-21 21:21 hsuppr 阅读(313) 评论(0) 推荐(0) 编辑
摘要: 坐标变换看图B - G 是原来的一个单位B - J 也是。我们发现 切比雪夫距离 可以在坐标旋转后转换为 曼哈顿距离 。而曼哈顿距离可以在O(n)内计算出(求出每个x到xi的距离,同理求y,相加求和即可);具体可以看我的代码:/** * Problem:Meeting * Author:Shun Yao * Time:2013.5.21 * Result:Accepted */#include <cstring>#include <cstdlib>#include <cstdio>#include <algorithm>long n;long l 阅读全文
posted @ 2013-05-21 21:16 hsuppr 阅读(201) 评论(0) 推荐(0) 编辑