hdu 4790 Just Random 神奇的容斥原理】的更多相关文章

/** 大意: 给定[a,b],[c,d] 在这两个区间内分别取一个x,y 使得 (x+y)%p = m 思路:res = f(b,d) -f(b,c-1)-f(a-1,d)+f(a-1,c-1); f(b,d ) 表示在[0,b],[0,d] 之间有多少个符合上述要求的数 1.将[0,b] 分为两部分, b/p 和 b%p 能整除p的[0,(b/p)*p] 和[(b/p)*p+1,b ] 同理[0,d]也可以这样分, 这样对于[0,b] [0,d ] 分别有两种情况,则一共有四种情况. a.…
链接:pid=4790">http://acm.hdu.edu.cn/showproblem.php?pid=4790 意:从[a.b]中随机找出一个数字x,从[c.d]中随机找出一个数字y.给出p.m,假设(x+y)%p==m则算成功,问成功的概率是多少. 思路:[a.b]中连续p个数.[c,d]中连续p个数.用这2*p个数进行组合能找到p种的成功组合(详细不证),所以找到[a.b]中p循环的个数x1,[c,d]中p循环的个数y1,则它们组成的成功组合数为p*x1*y1. 然后是处理边界…
Just Random Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 87    Accepted Submission(s): 34 Problem Description Coach Pang and Uncle Yang both love numbers. Every morning they play a game with…
题意:在[a,b]  [c,d] 之间,和模p等于m的对数 详见代码 #include <stdio.h> #include <algorithm> #include <string.h> #include<cmath> #define LL long long using namespace std; int T; LL a,b,c,d,p,m; LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; } LL…
Problem Description Coach Pang and Uncle Yang both love numbers. Every morning they play a game with number together. In each game the following will be done: . Coach Pang randomly choose a integer x in [a, b] with equal probability. . Uncle Yang ran…
思路:对于a<=x<=b,c<=y<=d,满足条件的结果为ans=f(b,d)-f(b,c-1)-f(a-1,d)+f(a-1,c-1). 而函数f(a,b)是计算0<=x<=a,0<=y<=b满足条件的结果.这样计算就很方便了. 例如:求f(16,7),p=6,m=2. 对于x有:0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 对于y有:0 1 2 3 4 5 0 1 很容易知道对于xy中的(0 1 2 3 4 5)对满足条件的数目为p…
题目:hdoj 4790 Just Random 题意:给你两个闭区间[a,b],[c,d],分别从中等可能的跳出 x 和 y ,求(x+y)%p == m的概率 分析: 假如是[3,5] [4,7]   p = 2 . m = 1: 则全部的和 7 8 9 10 8 9 10 11 9 10 11 12 1 2 3 3 2 1 后面一行出现次数,能够发现能够分成三部分.第一部分递增的等差数列,第二部分值都相等,第三部分等差数列 然后用等差数列求和公式求和就ok AC代码: #include<i…
Just Random Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3932 Accepted Submission(s): 1276 Problem Description Coach Pang and Uncle Yang both love numbers. Every morning they play a game with n…
Coach Pang and Uncle Yang both love numbers. Every morning they play a game with number together. In each game the following will be done:  1. Coach Pang randomly choose a integer x in [a, b] with equal probability.  2. Uncle Yang randomly choose a i…
http://acm.split.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Special Judge Problem Description   In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, for example, if you collect all the 108 people i…