每场比赛要有局数限制才会产生平局的情况吧?
所在版块:求学狮城 发贴时间:2008-12-04 15:15

用户信息
复制本帖HTML代码
高亮: 今天贴 X 昨天贴 X 前天贴 X 
如果加入每场比赛局数限制,修改后的代码如下:

import java.util.*;

public class Tennis
{
public static void main(String[] args)
{
Random random = new Random();
int aWin = 0, bWin = 0;
int n = (new Scanner(System.in)).nextInt(); // n为比赛场数
int m = (new Scanner(System.in)).nextInt(); // m为每场比赛回合数
for (int i = 0; i < n; i++)
{
int aScore = 0, bScore = 0, j = 0;
while (Math.abs(aScore - bScore) < 2 && j < m)
{
int game = Math.abs(random.nextInt() % 3);
if (game == 0 || game == 1)
aScore++;
else
bScore++;
if (aScore - bScore >= 2)
aWin++;
else if (bScore - aScore >= 2)
bWin++;
j++;
}
}
System.out.println((double) aWin / n * 100 + "%\n" +
(double) bWin / n * 100 + "%\n" + (100 - (double) (aWin + bWin) / n * 100) + "%\n");
}
}

如果限制10局,甲胜的概率貌似接近78.6几,几个测试结果:

100
10
75.0%
25.0%
0.0%

1000
10
79.10000000000001%
19.6%
1.2999999999999972%

10000
10
78.59%
19.45%
1.9599999999999937%

100000
10
78.513%
19.744999999999997%
1.7420000000000044%

10000000
10
78.61402%
19.653409999999997%
1.7325699999999955%

10000000
10
78.63001%
19.63833%
1.731660000000005%

10000000
10
78.60665%
19.65362%
1.7397299999999944%
.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!

 相关帖子 我要回复↙ ↗回到正文
有趣的网球输赢概率题 spinach   (168 bytes , 1081reads )
Solve the Discrete Time Markov Chain simon   (0 bytes , 475reads )
题目修改 spinach   (308 bytes , 287reads )
0.855967? hash   (119 bytes , 315reads )
应该是80%吧,一个小程序模拟进行10000000场比赛输出结果接近80% MetalGearSnake   (976 bytes , 404reads )
有没有办法把平局也放进去?? spinach   (186 bytes , 271reads )
每场比赛要有局数限制才会产生平局的情况吧? MetalGearSnake   (1321 bytes , 288reads )
if you know sth about stochastic, this is a stopping-time problem 1300cc   (102 bytes , 284reads )
试着写一般表达式,这样对吗? spinach   (79 bytes , 244reads )
what is the general formula for the stopping time? spinach   (214 bytes , 239reads )
yes. it's a typo in my first equation. should be -2 , not -1/2 1300cc   (15 bytes , 291reads )
it's in this way 1300cc   (67 bytes , 372reads )
for stopping-time problems, there are no "draw"? spinach   (0 bytes , 253reads )
no draw 1300cc   (192 bytes , 256reads )
我的答案跟大家一样4:1;可是好像不对 spinach   (521 bytes , 259reads )
如果不限制盘数的话,平局的概率为零 香陵居士   (0 bytes , 322reads )
考虑到状态稳定的时候 icky   (102 bytes , 288reads )
这个好 胡萝卜   (0 bytes , 240reads )
若不限制,甲80%,乙20%;若限制,自己算 冷色蓝天   (439 bytes , 291reads )
一场比赛多少盘?还是不限制盘数? 香陵居士   (0 bytes , 361reads )
不限盘数 spinach   (0 bytes , 265reads )
每胜一盘的[得]一分,另甲胜指甲胜整场比赛 spinach   (0 bytes , 208reads )