中国开发网: 论坛: 程序员情感CBD: 贴子 251147
没脾气2x: 我这程序是有问题,呵呵。海涛是对的咯咯
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++;
}

if ( m[kk[0]] )
{
sx = kk[1];
}
else
{
sx = kk[0];
}
}
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 );
}
}
}
}


嘎嘎

游戏 5730:
游戏者第一次选择: 0
主持人亮出 2 不是车。
游戏者不换选择, 仍选 0
游戏者得到车

游戏者没有交换次数为 2865,其中得到车的次数为 948
游戏者选择交换次数为 2865,其中得到车的次数为 1922
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)a

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录