题目链接:https://cn.vjudge.net/contest/208908#problem/H
大致题意:给你t个老虎和d个小鹿,再加上你,按照题目描述的规则每天随机抽取两个,问你存活的概率。
题解:按照题意,我们知道只有老虎才能吃老虎,并且他们会同归于尽,所以很容易想到当老虎的个数为奇数个时人一定不能存活,当老虎的数量为0时,人一定能存活,剩下的就是老虎的数量为偶数的情况了。我们知道在足够长的时间里,小鹿一定都被老虎吃掉了,所以我们丢掉它,只剩下老虎和你了,你要想存活,呢老虎必须自相残杀,因此概率就是所有老虎同归于尽的概率。
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long ll;
#define eps 1e-8
double c(int x)
{
return (double)x*((double)x-1.0)/2.0;
}
int main(void)
{
int T,i,t,d,cases=0;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&t,&d);
printf("Case %d: ",++cases);
if(t==0)
{
printf("1.0000000\n");
continue;
}
if(t%2==1)
{
printf("0.0000000\n");
continue;
}
double ans=1.0;
while(t)
{
ans*=((double)t-1.0)/((double)t+1.0);
t-=2;
}
printf("%.7f\n",ans);
}
return 0;
}