扑克牌概率问题
2010-11-14 20:08
267 查看
题目: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;
}
题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;
}
相关文章推荐
- 算法面试经常出现的问题——扑克牌中顺子和同花哪一个概率大?
- 石油大OJ 1023 问题 L: Pong’s Birds【概率Dp】
- 一个游戏引发的思考(概率问题)
- 关于扑克牌的简单排序问题
- 概率问题总结
- 用几何(解析几何)方法求解概率问题
- 概率dp-九度-1546-迷宫问题
- 蒲丰投针概率问题
- KMP算法与一个经典概率问题
- 概率DP种类问题 UVA - 10648 && CodeForces - 768D
- 海量数据等概率随机选取问题
- 【100题】第六十六~第七十题(颠倒栈、扑克牌顺子和掷骰子概率、数字数组排成最小数、求旋转数组中最小值、全排列)
- 面试中的概率问题 - 数学期望(2) - 武器升级需要的宝石数
- 扑克牌游戏问题
- lottery概率问题
- 概率题之疯子坐飞机问题 :(
- 等概率随机数问题
- 待填——升级武器的概率问题
- 阿里 骰子概率问题
- 随机算法java实现(同生日问题以及扑克牌24数问题)