BZOJ 2318: Spoj4060 game with probability Problem 概率
来源:互联网 发布:ueditor java图片上传 编辑:程序博客网 时间:2024/05/16 18:14
2318: Spoj4060 game with probability Problem
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 387 Solved: 183
[Submit][Status][Discuss]
Description
Alice和Bob在玩一个游戏。有n个石子在这里,Alice和Bob轮流投掷硬币,如果正面朝上,则从n个石子中取出一个石子,否则不做任何事。取到最后一颗石子的人胜利。Alice在投掷硬币时有p的概率投掷出他想投的一面,同样,Bob有q的概率投掷出他相投的一面。
现在Alice先手投掷硬币,假设他们都想赢得游戏,问你Alice胜利的概率为多少。
Input
第一行一个正整数t,表示数据组数。
对于每组数据,一行三个数n,p,q。
Output
对于每组数据输出一行一个实数,表示Alice胜利的概率,保留6位小数。
Sample Input
1 0.5 0.5
Sample Output
HINT
数据范围:
1<=t<=50
0.5<=p,q<=0.99999999
对于100%的数据 1<=n<=99999999
题解:
如果想选,对于
有
所以
如果想选,对于
有
所以
整理得:
然后剩
然后对于不想选的情况,那么
然而这样就没法用矩阵乘法了。。。
就需要黑科技,,当n很大时,其实概率已经基本不动了,,让n=min(n,1000)就好了Qwq。
#include<cmath>#include<ctime>#include<cstdio>#include<cstring>#include<cstdlib>#include<complex>#include<iostream>#include<algorithm>#include<iomanip>#include<vector>#include<string>#include<bitset>#include<queue>#include<map>#include<set>using namespace std;typedef double db;inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch<='9'&&ch>='0'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}return x*f;}const int N=1010;db f[N],g[N];int main(){int T=read();while(T--){int n=min(read(),1000);db p,q;g[0]=1;scanf("%lf%lf",&p,&q);for(int i=1;i<=n;i++){if(f[i-1]>g[i-1])p=1-p,q=1-q;f[i]=(p*g[i-1]+(1-p)*q*f[i-1])/(1-(1-p)*(1-q)); g[i]=(q*f[i-1]+(1-q)*p*g[i-1])/(1-(1-p)*(1-q)); if(f[i-1]>g[i-1])p=1-p,q=1-q;}printf("%.6lf\n",f[n]);}return 0;}
- 【BZOJ 2318】Spoj4060 game with probability Problem 概率
- [BZOJ 2318]Spoj4060 game with probability Problem:概率
- BZOJ 2318: Spoj4060 game with probability Problem 概率
- 【BZOJ】【P2318】【Spoj4060 game with probability Problem】【题解】【概率DP】
- 概率DP Spoj4060 game with probability Problem
- bzoj 2318: Spoj4060 game with probability Problem (概率与期望DP)
- 2318: Spoj4060 game with probability Problem|概率与期望
- 【BZOJ2318】【spoj4060】game with probability Problem 概率DP
- BZOJ_P2318 SPOJ4060 game with probability Problem(概率动态规划)
- [BZOJ2318]Spoj4060 game with probability Problem(概率dp)
- 【bzoj2318】Spoj4060 game with probability Problem 概率dp
- [BZOJ2318][SPOJ4060]Game with probability Problem 概率DP
- bzoj2318 Spoj4060 game with probability Problem
- 【bzoj2318】 Spoj4060 game with probability Problem
- 【bzoj2318】Spoj4060 game with probability Problem
- Game with probability Problem
- bzoj2318Spoj4060 game with probability Problem 期望DP
- SPOJ 4060 A game with probability
- rpm修复
- ZOJ2412 Farm Irrigation (DFS)
- 反射机制
- kaggle 里的ensemble函数,抄一个
- 判断某个页框pfn是否有效(section和root)
- BZOJ 2318: Spoj4060 game with probability Problem 概率
- 2.6将图标添加到菜单命令
- 类的初始化
- js中click事件被多次执行
- mybatis 自增主键配置
- 如何关闭 Mac 开机时发出的「咚」的声音?
- 剑指offer面试题[8]-旋转数组的最小数字
- Angular2之入门示例
- gzip工具类 支持字符串压缩解压缩