HDU1410
2014-02-25 16:51
316 查看
题意:给2个人的HP跟AP,求A获胜的概率
分析:A需要打败B n2=(HP2/AP1)向上取整次才能获胜
B需要打败A n1=(HP1/AP2)向上取整次才能获胜
当A获胜时,B可能打败A 0~n1-1次,P(B打败Ai次)=C(i,n2+i-1)*pow(0.5, n2+i);
C(x+1,y+1)=C(x,y)*(y+1)/(x+1);
分析:A需要打败B n2=(HP2/AP1)向上取整次才能获胜
B需要打败A n1=(HP1/AP2)向上取整次才能获胜
当A获胜时,B可能打败A 0~n1-1次,P(B打败Ai次)=C(i,n2+i-1)*pow(0.5, n2+i);
C(x+1,y+1)=C(x,y)*(y+1)/(x+1);
#include <iostream> #include<cstdio> #include<algorithm> #include<string> #include<cmath> #include<cstring> #define eps 1e-7 using namespace std; double ans; int main() { double tmp; int hp1,hp2,n1,i,n2,ap1,ap2; while(~scanf("%d%d%d%d",&hp1,&hp2,&ap1,&ap2)){ n1=hp1/ap2; if(n1*ap2!=hp1) n1++; n2=hp2/ap1; if(n2*ap1!=hp2) n2++; ans=pow(0.5,n2); tmp=0.0; for(i=1;i<=n1-1;i++){ tmp+=log10((i+n2-1)*1.0)-log10(i*1.0); ans+=pow(10.0,tmp+(i+n2)*log10(0.5)); } printf("%.4lf\n",ans*100.0); } return 0; }
相关文章推荐
- Android的Activity的launchMode与onActivityResult方法的关系
- 【Android进阶】android:configChanges属性总结
- Linux crontab 任务调度的使用
- 个性二维码,三分钟搞定,愤怒的小鸟!
- 类加载器2---父类委托机制
- Android Intent.FLAG_NEW_TASK详解,包括其他的标记的一些解释
- EASY_PAT_ZJU_1046 求循环数字公路中两个出口的最短距离
- ARPG手机网游java服务端主程初哥遇到的一些坑总结
- lab 2
- platform平台设备驱动简化示例代码
- opencv中测量运行时间的函数
- 实用简单 网页电子时钟
- [汇编语言]-第七章 SI和DI
- 图解 Ecplise 安装Aptana
- 余额宝正在合法“挤兑”银行存款
- SharePoint 2010 Ribbon的实现
- 并查集(A - Friendship)
- SharePoint 2010 Ribbon的实现
- 一招教你学会C C++混编
- smarty模板中获取页面session、get、post等参数