码迷,mamicode.com
首页 > 其他好文 > 详细

CSU 1265: Dice (数学啊 )

时间:2014-12-10 19:51:24      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:数学   csu   

题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1265


Description

An example of a traditional dice is a rounded cube, with each of its six faces showing a different number of dots from 1 to 6. When thrown or rolled, the dice comes to rest showing on its upper surface a random integral points from one to six, each value being equally likely.

----wikipedia

bubuko.com,布布扣

Now we have two dices which both have six faces. Can you tell us the probability that the sum points of two dices equals S when we thrown?

Input

There is an integer T (1 <= T <= 11) in the first line, means there are T test cases in total.

For each test case, there is only one line with one integer S (2 <= S <= 12), which have the same meaning as above.

Output

For each test case, you should print the probability that the sum points of two dices equals S when we thrown. The answer should be in one line and rounding to 6 decimals.

Print a blank line after each test case.

Sample Input

2
2
3

Sample Output

0.027778

0.055556

HINT

Source


代码如下:

#include <cstdio>
int main()
{
    int t;
    int sum;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&sum);
        int cont=0;
        for(int i = 1; i <= 6; i++)
        {
            for(int j = 1; j <= 6; j++)
            {
                if(i+j==sum)
                    cont++;
            }
        }
        printf("%.6lf\n\n",cont/36.0);
    }

    return 0;
}


CSU 1265: Dice (数学啊 )

标签:数学   csu   

原文地址:http://blog.csdn.net/u012860063/article/details/41849711

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!