A - Play the Dice
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87326#problem/A

Description

There is a dice with n sides, which are numbered from 1,2,...,n and have the equal possibility to show up when one rolls a dice. Each side has an integer ai on it. Now here is a game that you can roll this dice once, if the i-th side is up, you will get ai yuan. What's more, some sids of this dice are colored with a special different color. If you turn this side up, you will get once more chance to roll the dice. When you roll the dice for the second time, you still have the opportunity to win money and rolling chance. Now you need to calculate the expectations of money that we get after playing the game once.

Input

Input consists of multiple cases. Each case includes two lines. 
The first line is an integer n (2<=n<=200), following with n integers a i(0<=a i<200) 
The second line is an integer m (0<=m<=n), following with m integers b i(1<=b i<=n), which are the numbers of the special sides to get another more chance.

Output

Just a real number which is the expectations of the money one can get, rounded to exact two digits. If you can get unlimited money, print inf.

Sample Input

6 1 2 3 4 5 6
0
4 0 0 0 0
1 3

Sample Output

3.50
0.00

HINT

题意

一个n面的骰子,每一面有分值,并且扔到某些面的时候,可以再扔一次,然后问你最后得分的期望是多少

题解

  设期望值为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;

    当n==m时,为inf;

    否则为sum/(n-m).

代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//*************************** int main()
{
int n;
int hh;
while(cin>>n)
{
double sum=;
double a[];
for(int i=;i<=n;i++)
{
a[i]=read();
sum+=a[i];
}
int m;
cin>>m;
for(int i=;i<=m;i++)
{
hh=read();
}
if(sum==)cout<<<<endl;
else
if(n==m)cout<<"inf"<<endl;
else
printf("%.2f\n",sum/(n-m));
}
return ;
}

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. 概率DP HDU 4586 play the dice

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

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

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

  4. HDU 4586 Play the Dice (数学,概率,等比公式,极限)

    题意:给你一个n面的骰子每个面有一个值,然后其中有不同值代表你能获得的钱,然后有m个特殊的面,当你骰到这一面的时候可以获得一个新的机会 问你能得到钱的期望. 析: 骰第一次     sum/n 骰第二 ...

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

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

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

  7. HDU 5955 Guessing the Dice Roll

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

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

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

  9. HDU 2096 小明A+B --- 水题

    HDU 2096 /* HDU 2096 小明A+B --- 水题 */ #include <cstdio> int main() { #ifdef _LOCAL freopen(&quo ...

随机推荐

  1. angular2怎么使用第三方的库(jquery等)

    网上找了很多教材都搜索不到该部分类型,自己测试了下写了该教程. 场景说明:项目需要使用bootstrap,众所周知bootstrap没有时间日期控件的,需要使用第三方控件,我对如何在angular2中 ...

  2. 实现JavaScript自定义函数的整合、链式调用及类的封装

    函数声明形式:表单验证函数 1 2 3 4 5 6 7 8 9 10 11 12 13 function checkName(){     console.log('检查用户名'); } functi ...

  3. logback logback.xml常用配置详解(三)

    logback logback.xml常用配置详解 <filter> <filter>: 过滤器,执行一个过滤器会有返回个枚举值,即DENY,NEUTRAL,ACCEPT其中之 ...

  4. JQUERY 模糊选择

    JQUERY 模糊选择        [属性名称]         匹配包含给定属性的元素      [att=value]       匹配包含给定属性的元素      [att*=value]   ...

  5. 幼谈苹果新开发语言:Swift和苹果的用心

    今天是个值得纪念的日子:因为苹果的WWDC大会.苹果的每次WWDC(全球开发者大会)举行都让我们像打了肾上腺素这么兴奋.幸福.惊叹.震撼.深思. 今年也不例外,最关键的是苹果带来了它的一门新开发语言: ...

  6. 微信也能鉴别山寨iPhone【微信高级教程2】

    现在的技术真的很厉害,iPhone都能山寨几乎一样,外观不用说,系统UI都做得差不多相同,ytkah的一位朋友之前就被人骗了,她拿来手机让我优化,说是很卡,起初ytkah也琢磨很久,只是持怀疑态度,没 ...

  7. cocos进阶教程(3)Cocos2d-x多场景切换生命周期

    在多个场景切换时候,场景的生命周期会更加复杂.这一节我们介绍一下场景切换生命周期. 多个场景切换时候分为几种情况: 情况1,使用pushScene函数从实现HelloWorld场景进入Setting场 ...

  8. ubuntu上完全卸载package

    inux上完整的卸载apt方式安装软件的办法. 假设你的包叫做: your_pkg apt-get --purge remove your_pkg apt-get autoremove apt-get ...

  9. SCOPE_IDENTITY的作用

    SCOPE_IDENTITY返回插入到同一作用域中的 IDENTITY 列内的最后一个 IDENTITY 值.一个作用域就是一个模块——存储过程.触发器.函数或批处理.因此,如果两个语句处于同一个存储 ...

  10. jquery check box

    if ($("#eulaLine").is(':checked')) { var mobile = $("#mobile").val(); if (mobile ...