HDU 4586 Play the Dice (数学,概率,等比公式,极限)
题意:给你一个n面的骰子每个面有一个值,然后其中有不同值代表你能获得的钱,然后有m个特殊的面,当你骰到这一面的时候可以获得一个新的机会
问你能得到钱的期望。
析:
骰第一次 sum/n
骰第二次 sum/n*(m/n)
骰第三次 sum/n*(m/n)*(m/n)
骰第四次 sum/n*(m/n)*(m/n)*(m/n)
............
骰第k次
sum/n*(m/n)^k
即 sum/n*(1+q+q^2+q^3+……+q^k) q=m/n k=inf
所以 sum/n*(1/(1-m/n)) = (sum/n)*(n/n-m) =sum/(n-m)
那么 n=m时候期望无限大
notice sum等于0的时候直接输出 0.00
代码如下:
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 200 + 5;
const long double eps = 1e-1000;
int a[maxn]; int main(){
int n, m;
while(scanf("%d", &n) == 1){
int sum = 0;
for(int i = 0; i < n; ++i){
scanf("%d", &a[i]);
sum += a[i];
} scanf("%d", &m);
int x;
for(int i = 0; i < m; ++i)
scanf("%d", &x); if(!sum){
printf("%.2lf\n", 0.0);
continue;
}
else if(sum && m == n){
printf("inf\n");
continue;
} printf("%.2lf\n", sum*1.0/(n-m)); }
return 0;
}
HDU 4586 Play the Dice (数学,概率,等比公式,极限)的更多相关文章
- hdu 4586 Play the Dice(概率dp)
Problem Description There is a dice with n sides, which are numbered from 1,2,...,n and have the equ ...
- hdu 4586 Play the Dice (概率+等比数列)
Play the Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) To ...
- 概率DP HDU 4586 play the dice
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4586 解题思路: 只考虑第一次,获得的金币的平均值为sum/n.sum为所有色子的面的金币值相加. ...
- HDU 4586 Play the Dice(数学期望)
Play the Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- hdu 4586 Play the Dice 概率推导题
A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- hdu - 3959 Board Game Dice(数学)
这道题比赛中没做出来,赛后搞了好久才出来的,严重暴露的我薄弱的数学功底, 这道题要推公式的,,,有类似于1*a+2*a^2+3*a^3+...+n*a^n的数列求和. 最后画了一张纸才把最后的结果推出 ...
- hdu 4586 Play the Dice
思路:设期望值为s,前m个是再来一次机会,则有 s=(a[1]+s)/n+(a[2]+s)/n+……+(a[m]+s)/n+a[m+1]/n…… 化简:(n-m)s=sum 当sum=0时,为0: 当 ...
- HDU 5955 Guessing the Dice Roll
HDU 5955 Guessing the Dice Roll 2016 ACM/ICPC 亚洲区沈阳站 题意 有\(N\le 10\)个人,每个猜一个长度为\(L \le 10\)的由\(1-6\) ...
- hdu 5955 Guessing the Dice Roll 【AC自动机+高斯消元】
hdu 5955 Guessing the Dice Roll [AC自动机+高斯消元] 题意:给出 n≤10 个长为 L≤10 的串,每次丢一个骰子,先出现的串赢,问获胜概率. 题解:裸的AC自动机 ...
随机推荐
- 【BZOJ】1833: [ZJOI2010] count 数字计数(数位dp)
题目 传送门:QWQ 分析 蒟蒻不会数位dp,又是现学的 用$ dp[i][j][k] $ 表示表示长度为i开头j的所有数字中k的个数 然后预处理出这个数组,再计算答案 代码 #include < ...
- Druid.io系列(四):索引过程分析
原文链接: https://blog.csdn.net/njpjsoftdev/article/details/52956083 Druid底层不保存原始数据,而是借鉴了Apache Lucene.A ...
- HttpClient基础用法
一.HttpClient HttpClient是Apache HttpComponents 下的子项目,用来提供高效的.最新的.功能丰富的支持HTTP协议的客户端编程工具包(httpclient-4. ...
- 深入浅出 Java Concurrency (8): 加锁的原理 (Lock.lock)
接上篇,这篇从Lock.lock/unlock开始.特别说明在没有特殊情况下所有程序.API.文档都是基于JDK 6.0的. public void java.util.concurrent.lock ...
- update project maven项目的时候出错
preference node "org.eclipse.wst.validation"has been remove 上面的错误是因为修改包名无法互相引入导致的,仅仅需要将Ecl ...
- split分隔
split() : 把一个字符串分割成字符串数组 <script> var str="name=ww;value=ll"; var mm=str.split(" ...
- 新版Eclipse使用遇到的问题总结
1.SDK下载很慢. 配置SDK代理,速度像飞一样.建议先把20-24下完,不然后面遇到很多问题. 2.support-v7的问题 例如res\values\styles.xml:4: error: ...
- python找寻合适的日志库logging Handler——Handler自定义实现
最近在用python tornado开发一个app的服务端.投产的系统肯定需要包含日志功能,这里就自然想到了用python自带的logging库. logging中日志内容的输出都交由Handle ...
- HTTP接口开发专题二(发送http请求的接口工具类)
import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.IOException; imp ...
- **__new__和__init__
这个__new__之前在写单例模式的时候用到过,下面做个深入了解吧. __new__是一个静态方法,而__init__是一个实例方法. __new__方法会返回一个创建的实例,而__init__什么都 ...