hdu 4586 Play the Dice 概率推导题
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
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 ;
}
最新文章
- Intent(二)隐式调用intent
- 【BZOJ-4590】自动刷题机 二分 + 判定
- ASP.NET MVC4 &; Entity Framework 6.0 IIS 部署出错解决方案
- Mac快捷键 Xcode快捷键
- MongoDB(2):入门
- Java Lock
- Web打印控件smsx.cab使用说明
- windows linux—unix 跨平台通信集成控制系统----文件搜索
- python list用法
- 大数据入门到精通12--spark dataframe 注册成hive 的临时表
- 同步或者重构Activiti Identify用户数据的多种方案比较
- .3-浅析express源码之applicaiton模块(2)-app.render
- 使用 numpy.random.choice随机采样
- 初学Struts2
- iOS - 代码规范的提示
- linux中创建一个回收站
- 032-IDUtils 工具类模板
- 【ANSIBLE】ansible控制windows插件安装及运行error与解决方法
- HTML 参考手册- (HTML5 标准)
- mac下finder子目录直接打开终端