【题目大意】

Alice和Bob在玩一个游戏。有n个石子在这里,Alice和Bob轮流投掷硬币,如果正面朝上,则从n个石子中取出一个石子,否则不做任何事。取到最后一颗石子的人胜利。Alice在投掷硬币时有p的概率投掷出他想投的一面,同样,Bob有q的概率投掷出他相投的一面。

现在Alice先手投掷硬币,假设他们都想赢得游戏,问你Alice胜利的概率为多少。

【思路】

不会23333详细题解看这里:

详细的一些细节我放在注释里面了w

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=+;
double f[MAXN],g[MAXN],p,q; void solve()
{
int n;
scanf("%d",&n);
n=min(n,);
//由于n很大的时候,概率几乎不再发生改变,则只需要取和1000中较小的即可
scanf("%lf%lf",&p,&q);
f[]=,g[]=;
for(int i=;i<=n;i++)
{
if(f[i-]>g[i-])p=-p,q=-q;
//这里p和q表示的含义与题意不同,含义为当前投掷出正面朝上情况的概率
//如果还剩i-1个石头时,A先手更有利,则在还是i个石头的时候,A希望B拿掉当前石头,B也希望A拿掉,故均希望反面向上。
//这种情况下,正面朝上的概率就是1-p/1-q
//如果还剩i-1个石头时,A后手更有利,则两个人都希望自己能选,正面朝上的概率就是p/q
f[i]=(p*g[i-]+(-p)*q*f[i-])/(-(-p)*(-q));
g[i]=(q*f[i-]+(-q)*p*g[i-])/(-(-p)*(-q));
if(f[i-]>g[i-])p=-p,q=-q;
}
printf("%.6lf\n",f[n]);
} int main()
{
int T;
scanf("%d",&T);
while (T--) solve();
return ;
}

【期望DP】BZOJ2318-[Spoj4060]Game with probability Problem的更多相关文章

  1. BZOJ2318: Spoj4060 game with probability Problem

    #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #i ...

  2. 嘴巴题8 BZOJ2318: Spoj4060 game with probability Problem

    Time Limit: 1 Sec Memory Limit: 128 MB Submit: 555 Solved: 273 [Submit][Status][Discuss] Description ...

  3. 【BZOJ2318】Spoj4060 game with probability Problem 概率

    [BZOJ2318]Spoj4060 game with probability Problem Description Alice和Bob在玩一个游戏.有n个石子在这里,Alice和Bob轮流投掷硬 ...

  4. BZOJ 2318: Spoj4060 game with probability Problem( 概率dp )

    概率dp... http://blog.csdn.net/Vmurder/article/details/46467899 ( from : [辗转山河弋流歌 by 空灰冰魂] ) 这个讲得很好 , ...

  5. BZOJ 2318: Spoj4060 game with probability Problem (概率dp)(博弈论)

    2318: Spoj4060 game with probability Problem Description Alice和Bob在玩一个游戏.有n个石子在这里,Alice和Bob轮流投掷硬币,如果 ...

  6. 【BZOJ 2318】 2318: Spoj4060 game with probability Problem(概率DP)

    2318: Spoj4060 game with probability Problem Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 371  Sol ...

  7. 2318: Spoj4060 game with probability Problem

    2318: Spoj4060 game with probability Problem Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 356  Sol ...

  8. Bzoj 2318 Spoj4060 game with probability Problem

    2318: Spoj4060 game with probability Problem Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 524  Sol ...

  9. 【bzoj2318】Spoj4060 game with probability Problem 概率dp

    题目描述 Alice和Bob在玩一个游戏.有n个石子在这里,Alice和Bob轮流投掷硬币,如果正面朝上,则从n个石子中取出一个石子,否则不做任何事.取到最后一颗石子的人胜利.Alice在投掷硬币时有 ...

随机推荐

  1. solr笔记之安装部署到tomcat

    1. 下载 solr 去官网下载,下载的时候选清华的镜像源,这个页面:https://mirrors.tuna.tsinghua.edu.cn/apache/lucene/solr/7.1.0/ 在/ ...

  2. C++ Boost库 uBLAS 笔记

    构造 Vector #include <boost/numeric/ublas/vector.hpp> #include <boost/numeric/ublas/io.hpp> ...

  3. DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead extract-text-webpack-plugin 提取css报错

    深入浅出Webpack 1-5 使用pulugin extract-text-webpack-plugin 提取css报错 DeprecationWarning: Tapable.plugin is ...

  4. Verilog笔记.1.基本语法

    0.前 抽象模型分级: • 系统级(system):用高级语言结构实现设计模块的外部性能的模型.• 算法级(algorithm):用高级语言结构实现设计算法的模型.• RTL级(Register Tr ...

  5. redis中插入用户集合的语句,有四个属性

    一.redis 数据结构使用场景 原来看过 redisbook 这本书,对 redis 的基本功能都已经熟悉了,从上周开始看 redis 的源码.目前目标是吃透 redis 的数据结构.我们都知道,在 ...

  6. 64_n3

    nodejs-yamlish-0.0.5-9.fc26.noarch.rpm 11-Feb-2017 16:48 11966 nodejs-yargs-3.2.1-6.fc26.noarch.rpm ...

  7. https、socket、http协议

    一.https https 其实是由两部分组成:http+ssl(Secure Sockets Layer 安全套接层)/tls(Transport Layer Security 继任者安全传输层), ...

  8. 读书笔记 effective c++ Item 3 在任何可能的时候使用 const

    Const可以修饰什么?   Const 关键字是万能的,在类外部,你可以用它修饰全局的或者命名空间范围内的常量,也可以用它来修饰文件,函数和块作用域的静态常量.在类内部,你可以使用它来声明静态或者非 ...

  9. JavaScript 跳转 页面

    * window.location.href , self.location, window.location 出现问题不能跳转 Chome 不能本页跳转, IE 有时可以

  10. Struts2使用

    Struts2是一个基于MVC设计模式的Web应用框架.在MVC设计模式中,Struts2作为控制器(Controller)来建立模型与视图的数据交互.Struts 2是Struts的下一代产品,是在 ...