LightOJ - 1265 Island of Survival —— 概率
题目链接:https://vjudge.net/problem/LightOJ-1265
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 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 |
Output for Sample Input |
4 0 0 1 7 2 0 0 10 |
Case 1: 1 Case 2: 0 Case 3: 0.3333333333 Case 4: 1 |
题意:
一座岛上有t只老虎、d只鹿和1个人。枚举随机抽取两只动物(包括人)碰面。如果鹿遇鹿则无事;如果鹿遇虎,则鹿死;如果虎遇虎,则都死;如果人遇鹿,则鹿可能死也可能不死;如果人遇虎,则人死。问人生存的概率是多少?
题解:
1.可知,人能否存活只与老虎有关。
2.当老虎的数量为奇数时,人生存的概率为0。因为老虎是成对成对死的,那么最后必定能剩下一只老虎把人吃掉。
3.当老虎的数量为偶数时,只有在选中人与虎之前,老虎成对成对地死,人才有可能存活。
4.概率 P = C[t][2]/C[t+1][2]*C[t-2][2]/C[t-1][2]……*C[2][2]/C[3][2] = (t-1)/(t+1)*(t-2)/(t-1)*…… * 2/3 。
解释:由于鹿对人的存活没有影响,故可忽略其存在。C[t][2]/C[t+1][2]:从t只虎和1个人中选2个出来,2个都是老虎的概率。老虎一直递减、连乘是把老虎都解决完。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e5+; double dp[MAXN];
int main()
{
int T, t, d, kase = ;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &t,&d);
if(t%)
printf("Case %d: 0\n", ++kase);
else
{
double ans = 1.0;
while(t) ans *= 1.0*(t-)/(t+), t -= ;
printf("Case %d: %.10lf\n", ++kase, ans);
}
}
}
LightOJ - 1265 Island of Survival —— 概率的更多相关文章
- LightOJ - 1265 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 kin ...
- LightOJ.1265.Island of Survival(概率)
题目链接...我找不着了 \(Description\) 岛上有t只老虎,1个人,d只鹿.每天随机有两个动物见面 1.老虎和老虎碰面,两只老虎就会同归于尽: 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉 ...
- [LightOJ 1265] Island of Survival
Island of Survival You are in a reality show, and the show is way too real that they threw into an i ...
- LightOj 1265 - Island of Survival(概率)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1265 题目大意:有一个生存游戏,里面t只老虎,d只鹿,还有一个人,每天都要有两个生物碰 ...
- LightOJ - 1265 Island of Survival 期望
题目大意:有一个生存游戏,里面t仅仅老虎,d仅仅鹿,另一个人,每天都要有两个生物碰面,如今有下面规则 1.老虎和老虎碰面.两仅仅老虎就会同归于尽 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉对方 3.人 ...
- LightOJ 1065 Island of Survival (概率DP?)
题意:有 t 只老虎,d只鹿,还有一个人,每天都要有两个生物碰面,1.老虎和老虎碰面,两只老虎就会同归于尽 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉对方 3.人和鹿碰面,人可以选择杀或者不杀该鹿4. ...
- Island of Survival 概率
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> ...
- LightOj:1265-Island of Survival
Island of Survival Time Limit: 2 second(s) Memory Limit: 32 MB Program Description You are in a real ...
- LightOJ - 1265 (概率)
题意: 1.两只老虎相遇 就互相残杀 2.老虎与鹿相遇 鹿死 3.老虎与人相遇 人死 4.人与鹿相遇 鹿死 5.鹿与鹿相遇 无果 求人活的概率 解析:如果老虎为0 则人活得概率为1 ...
随机推荐
- 导出excel(利用工具类导出excel)
/** * 添加导出功能 * @param creditPageResult * @param request * @param response */ @RequestMapping(value = ...
- JavaScript实现网页元素的拖拽效果
以下的页面中放了两个div,能够通过鼠标拖拽这两个元素到任何位置. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamFja2ZydWVk/font/5a6 ...
- AutoCAD2004启动时出现fail to get CommcntrController的怎么办
解决AutoCAD2004启动时出现fail to get CommcntrController的问题! 2009-02-01 18:06 以前安装AutoCAD2004的时候可以用正常使用,后来又装 ...
- vue2.0 watch 详解
vue官网解释: 一个对象,键是需要观察的表达式,值是对应回调函数.值也可以是方法名,或者包含选项的对象.Vue 实例将会在实例化时调用 $watch(),遍历 watch 对象的每一个属性. 也就是 ...
- codeforces 486C Palindrome Transformation 贪心求构造回文
点击打开链接 C. Palindrome Transformation time limit per test 1 second memory limit per test 256 megabytes ...
- 怎样推断server为虚拟机还是物理真机?
dmidecode |grep -A20 "Memory Device$"|sed -n -e'/Locator/p' -e '/Size/p'|grep -v "Ban ...
- IT项目管理-----给年轻工程师的十大忠告
http://blog.csdn.net/hbqhdlc/article/details/6201179给年轻工程师的十大忠告 诸位,咱当电子工程师也是十余年了,不算有出息,环顾四周,也没有看见几个有 ...
- android:scrollbar的一些属性
1. activity_maim.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android ...
- [ 转]C++ 虚函数表解析
http://blog.csdn.net/haoel/article/details/1948051 前言 C++中的虚函数的作用主要是实现了多态的机制.关于多态,简而言之就是用父类型别的指针指向其子 ...
- [水]ZOJ1201
给原排列 求 其前面有多少个数比他大. 给每一个数1...2..n前面有多少个数比他大,求原序列 第一个直接统计 第二个从1開始找出第inv[i]+1个空位置放进去就好 printf里的format ...