light oj1265 Island of Survivalm
来源:互联网 发布:linux 软件安装方式 编辑:程序博客网 时间:2024/06/06 07:45
思路:首先留意到如果老虎的个数是奇数的话那么人就一定不能存活,因为老虎只有遇到老虎的时候才会死亡,换而言之奇数的话人总是会遇到老虎的,偶数的话稍微复杂一点,如果要人存活,那么就是老虎都要死亡,那么对于每一天来说老师相遇的概率就是 (t-1)*t / (t+1)*t,然后累乘就行,或者直接约分
#include<bits/stdc++.h>using namespace std;int main(){int T;int cas = 1;scanf("%d",&T);while (T--){int t,d;scanf("%d%d",&t,&d);if (t%2==1){printf("Case %d: 0\n",cas++);continue;}else{double ans = 1.0;for (int tt = t;tt>=2;tt-=2){ans*=double((tt-1)*tt) / double((tt+1)*tt);}printf("Case %d: %lf\n",cas++,ans);}}}
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
- light oj1265 Island of Survivalm
- light oj 1265 - Island of Survival(概率dp)
- 592 - Island of Logic
- 592 - Island of Logic
- uva592 - Island of Logic
- 592 - Island of Logic
- [Leetcode]Number of Island
- LightOJ1265 - Island of Survival
- LightOJ1265-Island of Survival
- Island of Survival LightOJ
- LightOJ1265---Island of Survival
- Island of Survival LightOJ
- Island of Survival LightOJ
- uva 592 Island of Logic
- UVa 592 - Island of Logic
- UVa 592 - Island of Logic
- UVA 592 - Island of Logic
- UvaOJ 592 Island of Logic
- 1007
- ARM Linux 3.x的设备树(Device Tree)
- HDU 2063过山车
- java web笔记——随机图片验证码实现看不清换一张
- vim常用快捷键
- light oj1265 Island of Survivalm
- WebStorm下使用TypeScript
- Device Tree(一):背景介绍
- poj 2709 Painter
- svn的很少用到的功能
- WebView显示网页
- Mi Ni DVD系统
- 转载学习内容
- 新贵妃醉酒