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

a) If you and a tiger meet, the tiger will surely kill you.

b) If a tiger and a deer meet, the tiger will eat the deer.

c) If two deer meet, nothing happens.

d) If you meet a deer, you may or may not kill the deer (depends on you).

e) If two tigers meet, they will fight each other till death. So, both will be killed.

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. 
Sample Input

Output for Sample Input

4

0 0

1 7

2 0

0 10

Case 1: 1

Case 2: 0

Case 3: 0.3333333333

Case 4: 1
 

 

题意:

t只老虎、d只鹿和1个人。一天会有两个动物相遇,规则:老虎遇到什么都吃,两只老虎遇到一起的话,同归于尽。

分析:

鹿和人的生死无关,因此忽略;

如果虎的数量是奇数时,人必死;

如果老虎数量是偶数时,对t+1个动物排队,总体有(t+1)!,假设前面的动物两两遇到,人要放在最后,所以成功存活的排堆:t!

ans=1/(t+1)

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#define nmax 510
using namespace std;
int cas=0,T,m,k,n;
double p;
int main(){

scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
if(n&1)
printf("Case %d: 0\n",++cas);
else
{

printf("Case %d: %.10lf\n",++cas,1.0/(n+1));
}

}


}