文章标题

这是一个概率问题,参赛者在一个岛屿上与老虎和鹿共存。每天两个动物相遇,根据不同的相遇情况,参赛者的生存状况会改变。目标是最大化赢得比赛的概率。输入包含老虎和鹿的数量,输出是获胜的预期概率。当老虎数量为偶数时,可以通过老虎自相残杀来确保生存,概率为1/(t+1),其中t是老虎的数量。代码实现中使用了C++,并简化了处理过程。
摘要由CSDN通过智能技术生成

Description

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

4

0 0

1 7

2 0

0 10

Sample Output

Case 1: 1

Case 2: 0

Case 3: 0.3333333333

Case 4: 1
题目很好理解,我这英语渣都看得懂。。。。
主要是要忽略掉deer的影响,我之前没想到。。。
然后wa了2发。。。
看了看别人的都写的循环,其实没必要。。。
如下
t个老虎,如果是奇数,那你必死;
偶数的话活下来的情况就是老虎都自相残杀啦;
t/(t+1)*(t-1)/t=(t-1)/(t+1)
然后继续连乘(t-1)/(t+1)*(t-3)/(t-1)~~~1/3;
约分后 ans=1/(t+1)
这样快多啦。。。
ac代码`

include

include

include

include

include

using namespace std;

define debug(x) cout<<#x<<’=’<

define ya(x) scanf(“%d”,&x)

define Cas(x) printf(“Case %d: “,x)

define wen(x) printf(“%d\n”,x)

define FOR(T) for(int cas=1;cas<=T;cas++)

int main()
{
int T;
//freopen(“input.txt”,”r”,stdin);
ya(T);
FOR(T)
{
int t,d;
cin>>t>>d;
Cas(cas);
if(t%2==0)
printf(“%lf\n”,1.0/(t+1));
else printf(“0\n”);
}
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值