HDU 4586 Play The dice (probability problem, push formula)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.