Problem Description:
There is a dice with n sides, which was numbered from,..., N and has the equal possibility to show up when one rolls a Dice. Each side have an integer AI on it. Now here's a game that's can roll this dice once, if the i-th side are up and you'll get Ai yuan. What's more, some SIDs of this dice is colored with a special different color. If you turn this side up, you'll get once more chance to roll the dice. When the dice is the second time, you still has the opportunity to win money and rolling chance. Now, need to calculate the expectations of money, we get after playing the game once.
Input:
Input consists of multiple cases. Each case includes the lines.
The first line is a integer n (2<=n<=200), following with n integers ai (0<=ai<200)
The second line is a integer m (0<=m<=n), following with M integers bi (1<=bi<=n), and which is the numbers of th e Special sides to get another more chance.
Output:
Just a real number which is the expectations of the one can get, rounded to exact, and digits. If you can get the 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
Problem Solving Ideas:
When n = = m, the output INF, otherwise the result is sum/(N-M);
#include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath > #include <vector> #include <queue> #include <stack> #include <set> #include <map># Define LL long longusing namespace Std;const int maxn = + 10;int main () { int sum, n, m; while (scanf ("%d", &n)!=eof) { sum = 0; int x; for (int i=0;i<n;i++) { scanf ("%d", &x); sum + = x; } scanf ("%d", &m); for (int i=0;i<m;i++) scanf ("%d", &x); if (sum = = 0) { printf ("0.00\n"); Continue; } if (n = = m) { printf ("inf\n"); Continue; } printf ("%.2lf\n", (double) sum/(n-m)); } return 0;}
HDU 4586 Play The dice (probability problem, push formula)