UVA 11500
来源:互联网 发布:制作搞笑图片软件 编辑:程序博客网 时间:2024/05/17 04:39
Thinking: This problem involves the gambler's ruin theorem.
wiki link
We can consider EV1/D , EV2/D as coins in the original problem. And in the theorem, P1,P2 represent the probability that person one or two's becoming penniless.
But here in the uva problem, the answer should be the probability that some one wins, thus p2 formula should be used.
AC code:
#include<iostream>#include<cmath>using namespace std;int main(){ int ev1,ev2,at,d; while(scanf("%d%d%d%d",&ev1,&ev2,&at,&d)) { if(ev1||ev2||at||d) { int ev1c = ceil(1.0*ev1/d); int ev2c = ceil(1.0*ev2/d); double p = 1.0*at/6;// p(vampire1 wins) double q = 1-p; double q_over_p = q/p; if(at == 3) { printf("%.1lf\n", 100.0*(double)ev1c/(ev1c+ev2c)); } else{ double p_v1_wins = 100*(1-pow(q_over_p,1.0*ev1c))/(1-pow(q_over_p,1.0*(ev1c+ev2c))); printf("%.1lf\n",p_v1_wins); } } else break; }return 0;}
0 0
- UVA 11500
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- export
- Xilinx System Generator模块中各个常见选项的含义
- mybatis-sql小结
- LintCode:N皇后问题
- Android 修改开机动画(bootanimation)
- UVA 11500
- 哈密尔顿环路问题
- HDU 1711 Number Sequence
- PHP项目开发流程
- struct stat结构体简介
- C++标准库,标准程序库,标准模板库之间是什么关系(重要!!!)
- 阅读
- [打字练习]Day Five
- Linux内存管理之一 分段与分页