LightOJ 1265 Island of Survival 概率DP

                H - Island of Survival

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Submit Status Practice LightOJ 1265

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

题意:你在岛上,岛上还有tiger,deer,每天会相遇一次,问你能存活下来的概率。

注意到:deer对你是否可以存活下来没有影响,不用管它

令dp[i]剩余i只tiger时,你存活下来的概率

则dp[0]=1.0;

若有奇数只tiger,你最后存活下来的概率为0

若有偶数只tiger,则dp[i]=(i-1)/(i+1)*dp[i-2];

先算出所有的dp[i]即可。

 1 #include<cstdio>
 2 #include<cstring>
 3
 4 const int MAXN=1010;
 5 double dp[MAXN];
 6
 7 int main()
 8 {
 9     dp[0]=1;
10     for(double i=1;i<1010;i++)
11     {
12         if(((int)i)%2)
13             dp[(int)i]=0.0;
14         dp[(int)i]=(i-1)/(i+1)*dp[(int)i-2];
15     }
16     int test;
17     scanf("%d",&test);
18     int cas=1;
19     while(test--)
20     {
21         printf("Case %d: ",cas++);
22         int t,d;
23         scanf("%d%d",&t,&d);
24         printf("%.8f\n",dp[t]);
25     }
26     return 0;
27 }

时间: 2024-08-11 05:42:49

LightOJ 1265 Island of Survival 概率DP的相关文章

LightOJ 1065 Island of Survival (概率DP?)

题意:有 t 只老虎,d只鹿,还有一个人,每天都要有两个生物碰面,1.老虎和老虎碰面,两只老虎就会同归于尽 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉对方 3.人和鹿碰面,人可以选择杀或者不杀该鹿4.鹿和鹿碰面,没事问人存活下来的概率 析:最后存活肯定是老虎没了,首先可以用概率dp来解决,dp[i][j] 表示 还剩下 i 考虑, j 只鹿存活的概率是多少. 然后每次分析这几种情况即可. 还有一种思路就是只要考虑老虎没了,只要老虎没了就能存活,只要计算老虎全死完的概率就好,首先如果老虎是奇数,是

LightOJ - 1265 Island of Survival 期望

题目大意:有一个生存游戏,里面t只老虎,d只鹿,还有一个人,每天都要有两个生物碰面,现在有以下规则 1.老虎和老虎碰面,两只老虎就会同归于尽 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉对方 3.人和鹿碰面,人可以选择吃或者不吃该鹿 4.鹿和鹿碰面,相安无事 问人存活下来的概率 解题思路:自己想复杂了,用了二维的dp... 看了别人的,发现根本不用dp,人生存下来的条件就是不被老虎吃掉,所以只要所有的老虎都同归于尽了,人就可以生存下来了 如果老虎的数量是奇数,那么人总有一天会被吃掉的 如果老虎的数

light oj 1265 - Island of Survival(概率dp)

1265 - Island of Survival PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB 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 t

LightOJ 1268 Island of Survival 数学神解/不用写那些guapi概率dp

谢谢Wen_kr的翻译 题目大意: 你困在一个岛上,上面有老虎和鹿,分别有 只与 只. 如果有一天,你和老虎相遇,那么你死,你和鹿相遇,那么你可以选择杀死或者不杀死这头鹿,老虎和鹿相遇,那么鹿死,鹿和鹿相遇,什么也不会发生,老虎与老虎相遇,那么它们会杀死对方. 每天仅能有一对动物相遇,问你不死并且所有老虎死掉的最大概率. 第一种解法:概率dp 设dp[i][j]为i头老虎j头鹿满足条件的概率...... 这个解法不重要,重要的是下一个. 第二种解法:数学贪心 尽量让老虎自相残杀 即当前老虎为t,

LightOJ1265---Island of Survival (概率dp)

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,

lightoj 1248-G - Dice (III) (概率dp)

题意:给你n个面的骰子,问扔出所有面的期望次数. 虽然这题挺简单的但还是要提一下.这题题目给出了解法. E(m)表示得到m个不同面的期望次数. E(m+1)=[((n-m)/n)*E(m)+1]+(m/n)*E(m+1); 想必((n-m)/n)*E(m)+1这个很好理解吧,当得到m个面时他有((n-m)/n)的概率得到没得到过的面 而(m/n)*E(m+1)不太好理解为什么,其实题目已经给出解释了,如果他有(m/n)的概率出到不同 面也有1-(m/n)的概率得到相同面,所以直接加上((n-m)

Island of Survival 概率

#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; int t,n,d; int main() { scanf("%d",&t); int cas=1; while(t--) { scanf("%d%d",&n,&d); printf("Ca

Lightoj 1038 - Race to 1 Again (概率DP)

题目链接: Lightoj  1038 - Race to 1 Again 题目描述: 给出一个数D,每次可以选择数D的一个因子,用数D除上这个因子得到一个新的数D,为数D变为1的操作次数的期望为多少? 解题思路: 概率DP咯,对于只知道期望是:E(X) = X1*p(X1) + X2*p(X2) + …… + Xn*p(Xn)的窝,拿这个题目没有一点办法.然后看了讨论版,发现总会有一些神人存在. 求操作次数的期望时,先设定第i个因子给期望的贡献为Ti,那么有:E = (T1 + T2 + T3

Codeforces Div.301D Bad Luck Island(概率dp+记忆化搜索)

一道概率dp问题. 题目链接:http://codeforces.com/contest/540/problem/D 题目大意:一个岛上有r个石头,s个剪子,p个布,他们之间随机挑出两个相遇,如果不是相同物种,就会有一个消失,分别求出最后这座岛上只剩下一个物种的概率. 我们用dp[i][j][k]来存储i个石头,j个剪刀,k个布时,某物种的存活概率,共dp三次,算出三个物种分别的概率. 首先,我们需要把对应想求的物种概率初始化,这里以石头为例,那么对于i从1到r,不难理解dp[i][0][0]=