题意:给你一个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 (数学,概率,等比公式,极限)的更多相关文章

  1. 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 ...

  2. hdu 4586 Play the Dice (概率+等比数列)

    Play the Dice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) To ...

  3. 概率DP HDU 4586 play the dice

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4586 解题思路: 只考虑第一次,获得的金币的平均值为sum/n.sum为所有色子的面的金币值相加. ...

  4. HDU 4586 Play the Dice(数学期望)

    Play the Dice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tot ...

  5. hdu 4586 Play the Dice 概率推导题

    A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  6. hdu - 3959 Board Game Dice(数学)

    这道题比赛中没做出来,赛后搞了好久才出来的,严重暴露的我薄弱的数学功底, 这道题要推公式的,,,有类似于1*a+2*a^2+3*a^3+...+n*a^n的数列求和. 最后画了一张纸才把最后的结果推出 ...

  7. 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: 当 ...

  8. HDU 5955 Guessing the Dice Roll

    HDU 5955 Guessing the Dice Roll 2016 ACM/ICPC 亚洲区沈阳站 题意 有\(N\le 10\)个人,每个猜一个长度为\(L \le 10\)的由\(1-6\) ...

  9. hdu 5955 Guessing the Dice Roll 【AC自动机+高斯消元】

    hdu 5955 Guessing the Dice Roll [AC自动机+高斯消元] 题意:给出 n≤10 个长为 L≤10 的串,每次丢一个骰子,先出现的串赢,问获胜概率. 题解:裸的AC自动机 ...

随机推荐

  1. python中包和模块的使用说明

    python中,每个py文件被称之为模块,每个具有__init__.py文件的目录被称为包.只要模块或者包所在的目录在sys.path中,就可以使用import 模块或import 包来使用. 如果想 ...

  2. 022:SQL优化--JOIN算法

    目录 一. SQL优化--JOIN算法 1.1. JOIN 写法对比 2. JOIN的成本 3. JOIN算法 3.1. simple nested loop join 3.2. index nest ...

  3. 009:JSON

    一. MySQL JSON类型 1. JSON介绍 什么是 JSON ? JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation) JSON 是轻量级 ...

  4. OD 实验(十三) - 对一个程序的逆向

    程序: 运行程序 点击 Start,它就会进行对系统的扫描 点击 About -> Enter Registration Code 随便输入一下内容,点击 OK,会弹出该弹窗 用 PEiD 看一 ...

  5. C 语言 - 逻辑运算和短路求值

    逻辑运算符: 运算符 含义 优先级 ! 逻辑非 高 && 逻辑与 中 || 逻辑或 低 举例: !a:如果 a 为真,!a 为假:如果 a 为 假,!a 为真 a && ...

  6. OD 实验(十一) - 对一个程序的破解

    程序: 点击安装程序 这是一个拼图程序 点击 Options -> Flash Sizes 程序会提示是未注册版本 点击一些选项的时候会提示该程序只给注册的用户 点击 Register 随便输入 ...

  7. CSRF进阶之打造一个检测CSRF漏洞的脚本

    前言: 还记得之前所学的CSRF漏洞吧.因为没有对表单做好对应的漏洞 而造成的CSRF漏洞.学了这个漏洞后逐渐的了解.这个比较鸡助. 代码: import requests,tqdm,time,os, ...

  8. Linux关闭iptables以及selinux

    1.查看iptables状态 /etc/init.d/iptables status # 方法1 service iptables status # 方法2 2.重启后永久生效 chkconfig i ...

  9. Python 小知识点(10)--异常结构记录

    try: print("try中") except KeyError as e: # 异常时,执行该块 print("异常中") else: # 主代码块(tr ...

  10. Maven Profiles 定义不同环境的参数变量

    应用场景 我们在开发的时候会遇到需要区分正式环境.测试环境.开发环境使用不同的参数,如数据库的用户名及密码等.这时可以用Spring 的PropertyPlaceholderConfigurer 来配 ...