【HDOJ】1222 Wolf and Rabbit】的更多相关文章

最大公约数,辗转相除. #include <stdio.h> long long gcd(long long a, long long b) { if (a<b) return gcd(b, a); if (!b) return a; else return gcd(b, a%b); } int main() { int case_n; long long m, n; scanf("%d", &case_n); while (case_n--) { scanf…
挺有意思的一道题目,解法是AC自动机+DP.AC自动机建立fail指针时,一定要注意结点的属性也需要传递.AC自动机结合了trie和kmp的优点.需要注意的是,每个模式串仅计算一次,否则这题很难解. /* 4057 */ #include <iostream> #include <sstream> #include <string> #include <map> #include <queue> #include <set> #inc…
HDU 1222   Wolf and Rabbit   (最大公约数)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88159#problem/G 题目: Description There is a hill with n holes around. The holes are signed from 0 to n-1.        A rabbit must hide in one of the holes…
[算法]高斯消元 [题解] 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或. 异或性质:00 11为假,01 10为真.与1异或取反,与0异或不变. 建图:对于图上每个点x列一条异或方程,未知数为n个灯按不按,系数为灯i按了点x变不变,该行结果n+1为初始状态.(所以a[x][y]其实表示x和y是否存在异或关系) 建图原理见上面链接. 寻找:因题目保证有解,而系数只有0或1,所以不用找最大,找到一个非0系数即可. 消元…
[题意]给定a和b,求满足a<=lcm(x,y)<=b && x<y的数对(x,y)个数.a,b<=10^11. [算法]莫比乌斯反演+组合计数 [题解]★具体推导过程参考:51nod1222 最小公倍数计数 过程运用到的技巧: 1.将所有i和j的已知因子提取出来压缩上届. 2.将带有μ(k)的k提到最前面,从而后面变成单纯的三元组形式. 最终形式: $$ans=\sum_{k=1}^{\sqrt n} \mu(k)  \sum_{d}    \sum_{i} \s…
Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9485    Accepted Submission(s): 4857 Problem Description There is a hill with n holes around. The holes are signed from 0 to n-1.…
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到boundry,使得boundry * n_edge - sum_edge <= k/b, 或者建立s->t,然后不断extend s->t. /* 4729 */ #include <iostream> #include <sstream> #include <…
Problem Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will…
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9848    Accepted Submission(s): 5011 Problem Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must hi…
http://wikioi.com/problem/1222/ 一开始我就想到这样构图的,即可能的连边.但是似乎无法判断. 然后想来想去想不出来.. 题解: 同样是二分图,将可能的连边,然后跑一次最大匹配,如果能完美匹配,那么就可能有肯定的信与信封,否则输出none,这点是显然的. 然后我们来考虑如何找出肯定的. 那么一定是在最大匹配的基础上,假设我们删了一个匹配(u, v),u却能匹配(即还是完美匹配),说明u肯定不是一个答案.因为它不唯一 反之如果不能完美匹配,说明他就是一个答案. 在标记的…