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.
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).
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
- hud 4790
- HUD
- HUD 1000
- HUD 1033
- HUD 4038
- HUD P1561
- HUD 4473
- HUD 4502
- Hud 4608
- hud 2073
- hud 1518
- HUD-1142
- Unity HUD
- UDK HUD
- hud 2795
- hud 4288
- hud Fibonacci
- hud 3713
- 一个耳熟能详的故事
- Windows Minifilter驱动 - DriverEntry (3)
- join,sort等命令
- jetty continuation基本原理及实现
- testlink中smarty的配置以及使用
- hud 4790
- 安装PHP常见错误解决error: libjpeg.(a|so),error: libpng.(a|so) not found,error: Cannot find ldap
- 网络编程的知识点笔记
- qt中使用opencv处理图片 QImage 和 IplImage 相互之间转换问题
- MVC使用ajax异步刷新时怎样输出从后台中传过来的JSON数据
- iOs 8 下载地址 (9月17日之后)
- IOS中http请求的cookie查看,删除,添加
- poj2010 Moo University - Financial Aid
- python出现Non-ASCII character '\xe7' in file ex6.py on line 1, but no encoding declare错误