LightOj:1265-Island of Survival
Island of Survival
Time Limit: 2 second(s) Memory Limit: 32 MB
Program 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
Output for Sample Input
Case 1: 1
Case 2: 0
Case 3: 0.3333333333
Case 4: 1
解题心得:
- 很有意思的一道题,如果很天真的跟着题意走,那就直接入坑了。其实,这里面的鹿根本没啥用啊
- 从思想上来理解,人遇到了鹿对人没影响,老虎遇到了鹿对老虎没影响,最后的概率只跟老虎和人有关系,所以在遇到鹿的情况直接忽略就当什么也没发生。
- 从数学上来理解,最后列出方程会发现,关于鹿的部分可以直接约分约掉,也是对于最后答案没有影响的。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
double dp[maxn];
double get_pro(double x,double y)
{
double x1 = y*(y-1.0);
double x2 = x*(x-1.0);
double ans = x2/x1;
return ans;
}
int main()
{
int T,cas = 1;
scanf("%d",&T);
while(T--)
{
memset(dp,0,sizeof(dp));
int t,d;
scanf("%d%d",&t,&d);
if(t%2 != 0)//如果老虎是单数,那么人必死
{
printf("Case %d: %.8f\n",cas++,0);
continue;
}
for(int i=0;i<=t;i+=2)
{
if(i == 0)
{
dp[i] = 1.0;
continue;
}
dp[i] = get_pro(i,i+1);
if(i >= 2)
dp[i] *= dp[i-2];
}
printf("Case %d: %.8f\n",cas++,dp[t]);
}
}
LightOj:1265-Island of Survival的更多相关文章
- LightOJ - 1265 Island of Survival —— 概率
题目链接:https://vjudge.net/problem/LightOJ-1265 1265 - Island of Survival PDF (English) Statistics F ...
- [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(概率)
题目链接...我找不着了 \(Description\) 岛上有t只老虎,1个人,d只鹿.每天随机有两个动物见面 1.老虎和老虎碰面,两只老虎就会同归于尽: 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉 ...
- LightOJ - 1265 Island of Survival 期望
题目大意:有一个生存游戏,里面t仅仅老虎,d仅仅鹿,另一个人,每天都要有两个生物碰面,如今有下面规则 1.老虎和老虎碰面.两仅仅老虎就会同归于尽 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉对方 3.人 ...
- 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 1065 Island of Survival (概率DP?)
题意:有 t 只老虎,d只鹿,还有一个人,每天都要有两个生物碰面,1.老虎和老虎碰面,两只老虎就会同归于尽 2.老虎和人碰面或者和鹿碰面,老虎都会吃掉对方 3.人和鹿碰面,人可以选择杀或者不杀该鹿4. ...
- 51Nod:1265 四点共面
计算几何 修改隐藏话题 1265 四点共面 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出三维空间上的四个点(点与点的位置均不相同),判断这4个点 ...
- LightOj:1030-Discovering Gold(期望dp模板)
传送门:http://www.lightoj.com/volume_showproblem.php?problem=1030 Discovering Gold Time Limit: 2 second ...
随机推荐
- Qt5.7中使用MySQL Driver(需要把libmysql.dll文件拷贝到Qt的bin目录中。或者自己编译的时候,链接静态库)
Qt5.7中使用MySQL Driver 1.使用环境 Qt5.7的安装安装就已经带了MySQL Driver,只需要在安装的时候选择一下即可.如果没有安装,可以采取自己编译的方式.在Qt的源码包的q ...
- Spark Mllib里决策树回归分析如何对numClasses无控制和将部分参数设置为variance(图文详解)
不多说,直接上干货! 在决策树二元或决策树多元分类参数设置中: 使用DecisionTree.trainClassifier 见 Spark Mllib里如何对决策树二元分类和决策树多元分类的分类 ...
- 关于eclipse安装maven之后,maven找不到JDK问题
问题: 最近在Eclipse里面装了maven之后,启动或者在运行项目时存在如下的警告: Eclipse is rinning in a JRE,but a JDK is require, Some ...
- SpringBoot 2.x (15):Actuator监控
Actuator监控:SpringBoot自带的,对生成环境进行监控的系统 使用:既然是监控,那就不能监控一个空项目 这里我使用SpringBoot整合MyBatis的Demo: https://ww ...
- 多线程----Thread类,Runnable接口,线程池,Callable接口,线程安全
1概念 1.1进程 进程指正在运行的程序.确切的来说,当一个程序进入内存运行,即变成一个进程,进程是处于运行过程中的程序,并且具有一定独立功能. 任务管理器中: 1.2线程 线程是进程中的一个执行单元 ...
- 零基础逆向工程15_C语言09_位运算
1.汇编中的移位指令 算数移位指令 指令格式:SAL/SAR Reg/Mem, CL/Imm SAL(Shift Arithmetic Left):算数左移 SAR(Shift Arithmetic ...
- 从零开始的Lua宅[1]:编译Lua解释器
Lua是一门神奇的脚本语言,游戏宅必备,懒人必备.Lua差多不是学起来用起来最简单的语言了,以至于简单到自身就是文档,自身就是配置文件.但是Lua的运行效率却是众多脚本中非常高的,据说仅次于V8爹下的 ...
- azure powershell 获取可用镜像列表
通过Azure Powershell 指定location和Pbulishername 获取所有可用镜像的 publisherName,Offer,Skus,Version,location信息列表 ...
- BZOJ 2539: [Ctsc2000]丘比特的烦恼
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 695 Solved: 260[Submit][Status][Discuss] Description ...
- python基础教程总结15——6 CGI远程编辑
功能: 将文档作为普通网页显示: 在web表单的文本域内显示文档: 保存表单中的文本: 使用密码保护文档: 容易拓展,支持处理多余一个文档的情况 1.CGI CGI(Comment Gateway I ...