1 条题解
-
0
C++ :
#include <stdio.h> #include <time.h> #include <stdlib.h> int main() { srand(time(0)); //随机数发生器初始化,不初始化的话每次结果就都一样了 int z[3];//存庄家掷的三个骰子的点数 int player;//存玩家掷的骰子的点数 int profit = 0;//庄家的盈利 int rep;//庄家掷的三个骰子有几个与玩家的骰子相同 for (int i = 0; i < 500000; i++) { rep=0; player=1+rand()%6; for (int j = 0; j < 3; j++) { z[j] = 1+rand()%6; if (player == z[j]) rep++; } switch (rep) { case 1: profit -= 1; break; case 2: profit -= 2; break; case 3: profit -= 6; break; default: if (player * z[0] == z[1] * z[2] || player * z[1] == z[0] * z[2] || player * z[2] == z[0] * z[1]) continue; else profit++; break; } }//模拟50万次结束 printf("%d%%\n",int(profit/5000.0)); return 0; }
- 1
信息
- ID
- 854
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者