You are in a reality show, and the show is way too real that they threw into an island. Only two kinds of animals are in the island, the tigers and the deer. Though unfortunate but the truth is that, each day exactly two animals meet each other. So, the outcomes are one of the following
If in some day you are sure that you will not be killed, you leave the island immediately and thus win the reality show. And you can assume that two animals in each day are chosen uniformly at random from the set of living creatures in the island (including you).
Now you want to find the expected probability of you winning the game. Since in outcome (d), you can make your own decision, you want to maximize the probability.
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each case starts with a line containing two integers t (0 ≤ t ≤ 1000) and d (0 ≤ d ≤ 1000) where t denotes the number of tigers and d denotes the number of deer.
Output
For each case, print the case number and the expected probability. Errors less than 10-6 will be ignored.
题意:
- 如果你和老虎相遇,老虎肯定会杀了你
- 如果老虎和鹿相遇,老虎就会吃掉鹿
- 如果两只鹿相遇,什么也不会发生
- 如果你遇到鹿,你可能会或可能不会杀死鹿(取决于你)
-
如果两个老虎相遇,两个老虎都将被杀死。
#include <iostream> using namespace std; int main() { int t = 0; cin >> t; for (int i = 1; i <= t; i++) { int n, m; cin >> n >> m; if (n%2==0) { double ans = 1; while (n != 0) { ans *= (n - 1)*1.0 / (n + 1); n -= 2; } printf("Case %d: %f\n", i, ans); } else { printf("Case %d: %d\n", i, 0); } } }