hud 4790

来源:互联网 发布:水弹玩具狙击枪 淘宝 编辑:程序博客网 时间:2024/04/29 07:53

点击打开杭电题目链接

Just Random

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1123    Accepted Submission(s): 308


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:
  1. Coach Pang randomly choose a integer x in [a, b] with equal probability.
  2. Uncle Yang randomly choose a integer y in [c, d] with equal probability.
  3. If (x + y) mod p = m, they will go out and have a nice day together.
  4. Otherwise, they will do homework that day.
  For given a, b, c, d, p and m, Coach Pang wants to know the probability that they will go out.
 

Input
  The first line of the input contains an integer T denoting the number of test cases.
  For each test case, there is one line containing six integers a, b, c, d, p and m(0 <= a <= b <= 109, 0 <=c <= d <= 109, 0 <= m < p <= 109).
 

Output
  For each test case output a single line "Case #x: y". x is the case number and y is a fraction with numerator and denominator separated by a slash ('/') as the probability that they will go out. The fraction should be presented in the simplest form (with the smallest denominator), but always with a denominator (even if it is the unit).
 

Sample Input
40 5 0 5 3 00 999999 0 999999 1000000 00 3 0 3 8 73 3 4 4 7 0
 

Sample Output
Case #1: 1/3Case #2: 1/1000000Case #3: 0/1Case #4: 1/1
 

Source
2013 Asia Chengdu Regional Contest
 





#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>#define ll long longusing namespace std;ll maxn, minn;ll tip;ll help(ll a){    if ((a<minn)||(a>maxn))        return 0;    else        return min(min(a-minn, maxn-a)+1, tip);}ll gcd(ll a, ll b){    if (b==0)        return a;    else return gcd(b, a%b);}int main(){    //freopen("in.txt", "r", stdin);    int t;    scanf("%d", &t);    int cc = 0;    while (t--)    {        cc++;        ll a, b, c, d, p, m;        scanf("%I64d %I64d %I64d %I64d %I64d %I64d", &a, &b, &c, &d, &p, &m);         minn = a+c;        maxn = b+d;        tip = min(b-a, d-c)+1;        ll tip1 = minn+tip-1;        ll tip2 = maxn-tip+1;        ll mp1 = max((ll)0, (tip1-m)/p);        ll mp2 = max((ll)0, (tip2-m)/p);                ll fp = max((ll)0, (minn-m-1)/p);        if ((m+fp*p)<minn)            fp++;        ll lp = max((ll)0, (maxn-m)/p);        ll ans1=0;        ll tmp1 = help(m+fp*p);        ll tmp2 = help(m+lp*p);                if (mp1<fp)            mp1 = fp-1;        else            ans1 += (2*tmp1+(mp1-fp)*p)*(mp1-fp+1)/2;                if (lp<=mp2)            mp2 = lp;        else            ans1 += (2*tmp2+(lp-mp2-1)*p)*(lp-mp2)/2;               ans1 += (mp2-mp1)*tip;        ll ans2 = (b-a+1)*(d-c+1);        ll gd  = gcd(max(ans1, ans2), min(ans1, ans2));        printf("Case #%d: ", cc);        printf("%I64d/%I64d\n", ans1/gd, ans2/gd);    }    return 0;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 淘宝充值流量没到账怎么办 微信手机充错了怎么办 支付宝充话费没到账怎么办 裤子摔了一个洞怎么办 顾客反应衣服质量不好怎么办 淘宝买的衣服味道很大怎么办 三国杀账号忘了怎么办 宽带连接被删了 怎么办 手机被偷了qq怎么办 手机丢了微信怎么办啊 手机店把手机修坏了怎么办 在手机店买到山寨机手机怎么办 有人在qq群上骂我怎么办 qq群一直有人骚扰怎么办 苹果手机QQ图标不在桌面上怎么办 苹果手机长按不能删除怎么办 qq发的图片过期怎么办 九黎八卦在仓库怎么办 飞猪f2领了万豪银卡没住怎么办 机械键盘摁键冲突怎么办 玩游戏键盘没反应怎么办 玩枪战游戏头晕恶心怎么办 手机看视频不能横屏怎么办 苹果手机安全码忘记了怎么办 信用卡安全码忘记了怎么办 联想电脑管家阻止我安装软件怎么办 word恢复后打开乱码怎么办 苹果手机局域网也登陆不了怎么办 剑三账号冻结7天怎么办 荒野行动无缘无故被限制时间怎么办 电脑打游戏闪屏怎么办 微信下载出现数据包出错怎么办 安卓平板闪退怎么办 剑侠世界2出了1怎么办 苹果手机有木马病毒删除不了怎么办 苹果手机病毒了怎么办【解决方法】 苹果手机点击病毒链接怎么办 苹果手机有病毒啦怎么办 苹果7p反复重启怎么办 苹果手机屏幕触屏不灵怎么办 苹果手机屏翘起来了怎么办