using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main( string[] args )
{
int max = 100000;
bool[] m = new bool[3];
int r, s1, sx, s2;
int cNonexchangeAll = 0, cNonexchangeGot = 0;
int cExchangeAll = 0, cExchangeGot = 0;
Random rand = new Random();
for ( int i = 1; i <= max; i++ )
{
Console.WriteLine( "\r\n\r\n游戏 {0}: ", i );
for(int j=0; j<3; j++)
{
m[j] = false;
}
r = rand.Next( 3 );
m[r] = true;
s1 = rand.Next(3);
Console.WriteLine( "游戏者第一次选择: {0}", s1 );
if ( m[s1] )
{
do
{
sx = rand.Next( 3 );
} while ( sx == s1 );
}
else
{
int[] kk = new int[2];
int k=0;
for(int j=0; j<3; j++)
{
if ( j == s1 )
{
continue;
}
kk[k] = j;
k++;
}
sx = kk[rand.Next( 2 )];
}
Console.WriteLine( "主持人亮出 {0} 不是车。", sx );
bool isexchange = (rand.Next( 2 ) == 0);
if ( isexchange )
{
s2 = 6 - (sx + 1) - (s1 + 1) - 1;
cExchangeAll++;
Console.WriteLine( "游戏者交换选择, 选择 {0}", s2 );
}
else
{
s2 = s1;
cNonexchangeAll++;
Console.WriteLine( "游戏者不换选择, 仍选 {0}", s2 );
}
if ( m[s2] )
{
if ( isexchange )
{
cExchangeGot++;
}
else
{
cNonexchangeGot++;
}
Console.WriteLine( "游戏者得到车" );
}
else
{
Console.WriteLine( "游戏者没得到车" );
}
Console.WriteLine();
Console.WriteLine( "游戏者没有交换次数为 {0},其中得到车的次数为 {1} ", cNonexchangeAll, cNonexchangeGot );
Console.WriteLine( "游戏者选择交换次数为 {0},其中得到车的次数为 {1} ", cExchangeAll, cExchangeGot );
}
}
}
}
游戏 100000:
游戏者第一次选择: 0
主持人亮出 1 不是车。
游戏者不换选择, 仍选 0
游戏者没得到车
游戏者没有交换次数为 50060,其中得到车的次数为 16670
游戏者选择交换次数为 49940,其中得到车的次数为 16586
Notemper2x 3.1 ( ̄ε( ̄#)
没脾气2x 之 个人综合篇:
http://notemper2x.cndev.org/
我的 panoramio 相册:
http://panoramio.com/user/zhaixudong
我的 flickr相册:
http://www.flickr.com/photos/notemper2x/
QQ号20250出售,售价400,000元整(5位、皇冠80级、VIP7)