|
|

楼主 |
发表于 2014-2-21 17:11
|
显示全部楼层
连进两次、单进一次、单不进一次、连不进两次,再进概率为0.9,0.8,0.6,0.5,求总进球数
|
楼上程序中
If k = "11" Then ';前次和上次均投进
If k = "01" Then ';前次未进,上次进
If k = "10" Then ';前次进,上次未进
If k = "00" Then ';前次及上次都未进
这四种情况的关系,应该是互相排斥的,每一次循环,只发生其中一种情况,只做一次。
可是因为你在后面几个 If 的前面少了 Else 语句,变成了前面做了后面还要再做的关系。
所以结果就不对了。
下面是我用 Pascal(Delphi) 语言编的程序以及计算结果:
var m,n,s: integer;
ss: longint;
k,kk: string;
a: real;
begin
randomize;
ss:=0;
for m:=1 to 1000 do
begin
if m mod 4=0 then k:=';11';;
if m mod 4=1 then k:=';01';;
if m mod 4=2 then k:=';01';;
if m mod 4=3 then k:=';00';;
kk:=k;
s:=0;
for n:=1 to 10000 do
begin
a:=random;
if k=';11'; then
begin
if a<=0.9 then
begin
s:=s+1; k:=';11';;
end
else
k:=';10';;
end
else if k=';01'; then
begin
if a<=0.8 then
begin
s:=s+1; k:=';11';;
end
else
k:=';10';;
end
else if k=';10'; then
begin
if a<=0.6 then
begin
s:=s+1; k:=';01';;
end
else
k:=';00';;
end
else if k=';00'; then
begin
if a<=0.5 then
begin
s:=s+1; k:=';01';;
end
else
k:=';00';;
end;
end;
writeln(m:5,kk:4,s:5);
ss:=ss+s;
end;
writeln;
writeln('; s = ';,ss/1000:6:2);
end.
---------------------------------------------------
1 01 8383
2 01 8342
3 00 8338
4 11 8300
5 01 8364
6 01 8341
7 00 8307
8 11 8414
9 01 8295
10 01 8291
11 00 8299
12 11 8389
13 01 8363
14 01 8333
15 00 8392
16 11 8304
17 01 8371
18 01 8274
19 00 8320
20 11 8394
21 01 8284
22 01 8314
23 00 8233
24 11 8412
25 01 8340
26 01 8372
27 00 8299
28 11 8312
…………
990 01 8318
991 00 8356
992 11 8274
993 01 8396
994 01 8340
995 00 8467
996 11 8320
997 01 8404
998 01 8345
999 00 8352
1000 11 8388
s = 8335.08
|
|