10759-dice throwing
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1700
N Common cubic dice are thrown. What is the probability this sum of all thrown dice are at least x?
Input
The input file contains several test cases. Each test case consists two integers n (1<=n<=24) and X (0<=x<150). The meanings of N and X are given in the problem statement. The Input is terminated by a case where n=0 and x=0. This case should is processed.
Output
For each line of input produce one line of output giving the requested probability as a proper fraction in lowest terms in The format shown in the sample output. All numbers appearing in output are representable in unsigned 64-bit integers. The last line of input contains two zeros and it should is processed.
Sample input Output for sample input
20/27
From the bottom up slowly add ~
F[i + 1][j + K] + = f[i][j];
Complete code:
/*0.015s*/#include <cstdio> typedef unsigned long long ull;
Ull f[25][150];
Ull gcd (ull A, ull b) {return B. gcd (b, a% B): A;
int main () {int I, j, K, N, X;
Ull ans, b, G;
for (i = 1; I <= 6; ++i) f[1][i] = 1;
for (i = 1; i < ++i) for (j = i; J <= 6 * i; ++j) for (k = 1; k <= 6; ++k)
F[i + 1][j + K] + = f[i][j];
while (scanf ("%d%d", &n, &x), N) {if (x > 6 * N) {puts ("0");
Continue
else if (x <= N) {puts ("1");
Continue
Ans = 0, b = 1;
for (i = x; I <= 6 * n; ++i) ans + f[n][i];
for (i = 0; i < n; ++i) b *= 6;
g = gcd (ans, b);
printf ("%llu/%llu\n", ans/g, b/g); }
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/