hdu 4586 Play the Dice 概率推导题
2015-08-16 14:08
363 查看
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).
代码:
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=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } //*************************** int main() { int n; int hh; while(cin>>n) { double sum=0; double a[500]; for(int i=1;i<=n;i++) { a[i]=read(); sum+=a[i]; } int m; cin>>m; for(int i=1;i<=m;i++) { hh=read(); } if(sum==0)cout<<0<<endl; else if(n==m)cout<<"inf"<<endl; else printf("%.2f\n",sum/(n-m)); } return 0; }
相关文章推荐
- Android的事件处理之监听与回调
- Bootstrap下拉菜单dropdown-menu
- 本科毕设-基于C8051单片机的身份识别系统设计
- swift入门-实现简单的登录界面
- HDU 4599 Dice 概率DP + 乘法逆元
- HDU1532 Drainage Ditches 【最大流量】
- mybatis学习2
- iOS
- [转]打造自己的LINQ Provider(上):Expression Tree揭秘
- lnmp 安装discuz
- java与C语言的数据类型对应
- POJ 1062 昂贵的聘礼(dijkstra)
- pat(A)1006. Sign In and Sign Out (结构体排序)
- poj2182 Lost Cows (线段树)
- HDU 5047 Sawtooth (JAVA大数类)
- [python leetcode] Word Ladder II (very hard)[非常难,放弃]
- poj2182 Lost Cows (线段树)
- PAT 01-2. Maximum Subsequence Sum (25) - Python
- ROADS
- 布局动画 属性初始 android:animateLayoutChanges