鱼C论坛

 找回密码
 立即注册
查看: 2641|回复: 1

题目205:骰子游戏

[复制链接]
发表于 2016-11-22 19:03:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
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 的形式给出你的答案。


小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-8-4 13:00:35 | 显示全部楼层
  1. #include<stdio.h>

  2. #define SIZE 36

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

  7. int main()
  8. {
  9.         int pyram[SIZE+1]={0,};
  10.         int cubic[SIZE+1]={0,};
  11.         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[i1+i2+i3+i4+i5+i6+i7+i8+i9]++;)))))))));
  12.         fun(1,6,fun(2,6,fun(3,6,fun(4,6,fun(5,6,fun(6,6,cubic[i1+i2+i3+i4+i5+i6]++;))))));

  13.         for(int i=1;i<=SIZE;i++)
  14.                 cubic[i]+=cubic[i-1];
  15.         long total=0;
  16.         for(int i=SIZE;i;i--)
  17.                 total+=(long)pyram[i]*cubic[i-1];
  18.         long double rate=total;
  19.         fun(0,6,rate/=6);
  20.         fun(0,9,rate/=4);

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

  22. }
复制代码

simple brute force
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-21 05:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表