题目打了个马虎眼仔细分析鹿并无卵用。
实际上是求老虎互相残杀都死最后只剩下人的概率
那有奇数个老虎必然最后剩下一只以上来吃人
偶数个时求最后老虎互相残杀全死的概率
(a+1)a/(a(a-1))
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int n;
int main()
{
int t,i1 = 1,n;
scanf("%d",&t);
while(t--)
{
int a,b;
scanf("%d%d",&a,&b);
printf("Case %d: ",i1);
i1++;
if(a&1)printf("0\n");
else{
double ans = 1.0;
while(a>0)
{
ans = ans*(a-1.0)/(a+1.0);
a-=2;
}
printf("%f\n",ans);
}
}
return 0;
}
本文介绍了一个关于老虎互相残杀直至全部死亡的概率计算问题,并提供了一段C++代码实现。当老虎数量为偶数时,通过迭代计算剩余老虎数量的概率,最终得到所有老虎互相残杀全死的概率。
254

被折叠的 条评论
为什么被折叠?



