Animaniacs Probability Puzzle: Dot's Transylvania Trip
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. \n\nBut to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. \n\nYakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. \n\nIt is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. \n\nInput Format\nThe only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. \n\nOutput Format\nOutput the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». \n\nC++ implementation: \ncpp\n#include <iostream>\n#include <algorithm>\n#include <cmath>\n\nint gcd(int a, int b) {\n if (b == 0)\n return a;\n return gcd(b, a % b);\n}\n\nint main() {\n int Y, W;\n std::cin >> Y >> W;\n\n int max_num = std::max(Y, W);\n int remaining_chances = 6 - max_num + 1;\n int numerator = remaining_chances;\n int denominator = 6;\n\n int divisor = gcd(numerator, denominator);\n numerator /= divisor;\n denominator /= divisor;\n\n std::cout << numerator << '/' << denominator << std::endl;\n\n return 0;\n}\n
原文地址: https://www.cveoy.top/t/topic/pRCS 著作权归作者所有。请勿转载和采集!