欧拉计划 发表于 2016-11-22 19:03:24

题目205:骰子游戏

Dice Game

Peter has nine four-sided (pyramidal) dice, each with faces numbered 1, 2, 3, 4.
Colin has six six-sided (cubic) dice, each with faces numbered 1, 2, 3, 4, 5, 6.

Peter and Colin roll their dice and compare totals: the highest total wins. The result is a draw if the totals are equal.

What is the probability that Pyramidal Pete beats Cubic Colin? Give your answer rounded to seven decimal places in the form 0.abcdefg.

题目:

Peter 有九个四面的(金字塔型)骰子,每个分别标上 1,2,3,4。
Colin 有六个六面(正方体)骰子,每个分别标上 1,2,3,4,5,6。

Peter 和 Colin 摇骰子,然后比较他们得到的总和:总和最高的获胜。如果相等的话,则是平局。
请问,金字塔 Peter 赢了正方体 Colin 的概率是多少?以七位小数 0.abcdefg 的形式给出你的答案。


fc1735 发表于 2018-8-4 13:00:35

#include<stdio.h>

#define SIZE 36

#define fun(x,y,z) \
for(int i##x=1;i##x<=y;i##x++){\
        z;\
}

int main()
{
        int pyram={0,};
        int cubic={0,};
        fun(1,4,fun(2,4,fun(3,4,fun(4,4,fun(5,4,fun(6,4,fun(7,4,fun(8,4,fun(9,4,pyram++;)))))))));
        fun(1,6,fun(2,6,fun(3,6,fun(4,6,fun(5,6,fun(6,6,cubic++;))))));

        for(int i=1;i<=SIZE;i++)
                cubic+=cubic;
        long total=0;
        for(int i=SIZE;i;i--)
                total+=(long)pyram*cubic;
        long double rate=total;
        fun(0,6,rate/=6);
        fun(0,9,rate/=4);

        printf("%.7Lf\n",rate);

}

simple brute force
页: [1]
查看完整版本: 题目205:骰子游戏