Probability calculation time limit: +Ms | Memory Limit:65535KB Difficulty:1
-
-
Describe
-
A and B two people take part in an answer contest. The process of the game is probably a and B two people take turns answer, a first answer. Once someone does not answer the question correctly, the opponent wins immediately. Therefore, two people in the game to a certain extent depends on the luck, I hope that they will not meet the problem later, and the opponent will encounter the problem. In order to simplify the problem, we assume that the probability of a correct problem is a%, b the probability of the problem is b%, ask the last A, B to win the game of the probability of each?
-
-
Input
-
-
Enter an integer t to indicate that there is a T group of test data.
Next T line, each line input two integers a, B, indicating that A and B wins the probability of a% and b% respectively, of which 0 <= a, b <=, AB < 10000.
-
-
Output
-
-
each set of test data output a row, respectively A and b the probability of the final win, the middle with 1 spaces separated. The probability is expressed in the form of the simplest fraction x/y (note that even if Y is 1, it should be written in x/1 form). The detailed output is shown in the sample example.
-
-
Sample input
-
-
2100 050 50
-
-
Sample output
-
-
1/1 0/11/3 2/3
-
-
Source
Beihang Network Qualifiers
#include <stdio.h> int GCD (int a,int b) {return!b?a:gcd (b,a%b);} int main () {int t;scanf ("%d", &t), while (t--) {int a,b,am,an,bm;scanf ("%d%d", &a,&b); if (a==0&&b) printf ("0/1 1/1\n"), else if (a&&b==0) printf ("1/1 0/1\n"), else if (a==0&&b==0) printf ("0/1 0/1\n"); else {am=a* (100-b); an=10000-a*b;bm=an-am; printf ("%d/%d%d/%d\n", AM/GCD (Am,an), AN/GCD (Am,an), BM/GCD (Bm,an), AN/GCD (Bm,an));} } return 0;}
nyoj-probability calculation