题目:http://zhidao.baidu.com/question/194835436.html
题2
有两副没有大小王的扑克,从中各抽一张,放回,判断是否相同(花色和点数相同)接着抽,抽52次,统计有多少对相同,进行以上实验1000次计算1000次中出现相同牌对数的平均数.
//头文件在之前文章中有写,
/*
BackPickFrom(box1);
void CardPlayer::BackPickFrom( CardBox& Box )
{
for( int i = 0 ; i < CardAmount ; ++i )
card[ i ] = Box.GetCard( rand() % Box.GetCardAmount() + 1 ) ;
}
*/
#include "CardPlayer.h"
int main()
{
/*
题2
有两副没有大小王的扑克,从中各抽一张,放回,
判断是否相同(花色和点数相同)接着抽,抽52次,
统计有多少对相同,进行以上实验1000次计算1000次中出现相同牌对数的平均数.
*/
CardBox box;
CardPlayer p1(1),p2(1);
int equal=0;
int time=0;
int loop=100000;
int amount=52;
for(int i=0;i<loop ;++i)
for(int j=0;j<amount ;++j,++time)
{
//p1.BackPickFrom(box1);
//p2.BackPickFrom(box2);
p1.BackPickFrom(box);
p2.BackPickFrom(box);
//cout<<"第"<<time<<"次取牌:/t";
//p1.DisplayCard();
//cout<<'/t';
//p2.DisplayCard();
if(p1.GetCardAt(1)==p2.GetCardAt(1))
{
++equal;
//cout<<"第"<<time<<"次"<<"Equal!/n";
}
}
cout<<"相等次数:"<<equal<<endl;
double count=equal;
cout<<"相等概率:"<<count/(loop*amount)<<endl;
return 0;
}