hdu 5776 抽屉定理】的更多相关文章

sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 2547 Accepted Submission(s): 973 Problem Description Given a sequence, you're asked whether there exists a consecutive subsequence whose sum i…
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=5776 Problem Description Given a sequence, you're asked whether there exists a consecutive subsequence whose sum is divisible by m. output YES, otherwise output NO Input The first line of the input has a…
链接:传送门 题意:给一个长为 n 的串,问是否有子串的和是 m 的倍数. 思路:典型鸽巢定理的应用,但是这里 n,m 的大小关系是不确定的,如果 n >= m 根据定理可以很简单的判定是一定有解的,当 n < m 的时候就需要去具体寻找一下了,这里构造一个新串 Si = a1 + a2 + a3 + ...... + ai ,如果新串 Si % m = 0 自然就yes了,对于任意一个串 Si % m 的余数范围在 [ 0 , m - 1 ] ,如果出现两个余数相同的新串 S 则就能构成 (…
sum 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5776 Description Given a sequence, you're asked whether there exists a consecutive subsequence whose sum is divisible by m. output YES, otherwise output NO Input The first line of the input has an i…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5776 题目让你求是否有区间的和是m的倍数. 预处理前缀和,一旦有两个数模m的值相同,说明中间一部分连续子列可以组成m的倍数. //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cstdlib>…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5776 求是否有区间的和是m的倍数 预处理前缀和,一旦有两个数模m的值相同,说明中间一部分连续子列可以组成m的倍数. 证明:若 x % m = b 且 y % m = b,那么x可以写成x = a1 * m + b,y可以写成y = a2 * m + b,(y - x) % m = ((a2 - a1) * m) % m = 0  假设1-n个数  sum[1-i]%m=sum[1-j]%m  所以s…
对于很大的组合数不能用C(n, m) = C(n - 1, m) + C(n-1, m -1)来求,这里就用到Lucas定理. 模板题: hdu3037:模板如下: #include <cstdio> using namespace std; ; typedef long long ll; ll F[maxn]; //求1-p所有的阶乘模上p void init(ll p) { F[] = ; ; i <= p; i++) F[i] = F[i - ] * i % p; } //求逆元…
假定n个数为a1,a2,...,an,前n项和分别是S1.S2.....Sn,那么如果有一个Si模n是0,就是答案,否则,n个数模n的余数只能在 1到n - 1之间,把余数作为抽屉,显然n个数放到n - 1个抽屉里面,肯定有两个数余数相等,这样取它们的差就得到了结果,算法复杂度是O(n)的. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> using na…
DIY CubeTime Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 207    Accepted Submission(s): 111 Problem Description Mr. D is interesting in combinatorial enumeration. Now he want to find out the numb…
题目链接 这题,明显考察搜索能力...在中文版的维基百科中找到了公式. #include <cstdio> #include <cstring> #include <string> #include <algorithm> using namespace std; #define MOD 1000000007 #define LL __int64 LL dp[]; ],flag[]; int main() { int i,n,t,j,num; LL x; n…