传送门1
传送门2
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 consists of multiple cases. Each case includes two lines.
The first line is an integer n(2<=n<=200) ,following with n integers ai(0<=ai<200)
The second line is an integer m(0<=m<=n) , following with m integers bi(1<=bi<=n) , which are the numbers of the special sides to get another more chance.
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.
6 1 2 3 4 5 6
0
4 0 0 0 0
1 3
3.50
0.00
有一个正n面体骰子,给出每个面的得分。接着是m,表示丢到哪些面后可以获得再掷一次的机会,问最后得分的期望。
显然这道题可以用概率dp/期望dp写
这里用另一种看起来很高端的写法.
第一次掷骰子获得分数期望显然是
printf("%.2lf\n",1.0*sum/(n-m));
n==m
时
puts("inf");
,但是别忘了
sum==0
的时候你运气再好一分都没有(
puts("0");
#include
#define N 205
int A[N],t;
int main() {
int n,m;
while(~scanf("%d",&n)) {
int sum=0;
for(int i=1;i<=n;i++) {
scanf("%d",&A[i]);
sum+=A[i];
}
scanf("%d",&m);
for(int i=1;i<=m;i++)scanf("%d",&t);//显然b[i]没有任何用处
if(sum==0)puts("0");
else if(n==m)puts("inf");
else printf("%.2lf\n",1.0*sum/(n-m));
}
return 0;
}