[ACM] Play the dice-mathematical probability

Source: Internet
Author: User

I haven't completed my questions for more than a year. Today I have made a water question for the competition. I feel the question is bitter and hard to understand.

Then, I read it several times, understood and thought, and achieved results.

There are two writable points:

1: Derivation, composition of the expected ans: First mean + undetermined mean

That is, ANS = (A1 +... An)/n + ans * M/N

Final Result: ANS = (A1 + .. An)/(n-M );

The formula also shows n! = M. The question can also be n = m. It is INF.

2: The accuracy problem. I used to make this mistake, but it was all vague. I paid special attention to it this time.

When judging sum = 0, use int to define sum to judge. AC, use double to judge expected

The most familiar wrong Anser...

The author also explained it in a little bit, providing two connections for everyone to learn. One is Microsoft's official materials.

A blog of step home

Http://technet.microsoft.com/zh-cn/library/system.double

Http://www.jb51.net/article/36935.htm

Do not spray a small white code ~ HA:

#include <stdio.h>int main(){    int n,m;    double ans;    while(scanf("%d",&n)==1)    {        int sum=0;        for(int i=0;i<n;i++)        {            int temp;            scanf("%d",&temp);            sum+=temp;        }        scanf("%d",&m);        for(int i=0;i<m;i++)        {            int temp;            scanf("%d",&temp);        }        if(sum==0)        {            printf("0.00\n");continue;        }        if(n==m)        {            printf("inf\n");continue;        }        ans=(double)sum/(n-m);        printf("%.2lf\n",ans);    }    return 0;}

Record a few URLs that are not carefully viewed:

Http://book.51cto.com/art/201204/326994.htm

Blog.csdn.net/xiaozzhao/article/details/7450042

Http://blog.csdn.net/sgnaw/article/details/12442

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.