当前位置:网站首页>赛尔号抽奖模拟求期望
赛尔号抽奖模拟求期望
2022-06-28 11:21:00 【熊三明】
九张牌,一开始都是反面,每次随机抽取三张更改牌面正反,下一次抽取在此次基础之上,直到所有牌面均为正时停止。求抽取次数的期望。并计算在两百次以内抽取完毕的概率。
通过二进制位有三个1的随机数迭代异或,实现连续翻牌的效果。因为二进制中1的位数为3的情况一共只有84种,因此可以先利用一个三层循环将其存储于s[84]中,可以排序验证一下。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int s[84]={0};
int cmp(const void *a,const void *b){
return *(int*)a-*(int*)b;}
int produce_random(void){
int n=rand()&511;
return n;
}
int randni(void){
int n=rand()%84;
return n;}
int expbi(const int n){
int m=1<<n;
return m;}
int main(int argc, char** argv){
int i=0,j,k,l;
int a,b,c;
int v=1000000;
for(j=0;j<7;j++){
for(k=j+1;k<8;k++){
for(l=k+1;l<9;l++){
s[i++]=expbi(j)+expbi(k)+expbi(l);
}
}
}
float sum=0.0;
//qsort(s,84,sizeof(int),cmp);
srand((unsigned int)time(NULL));
for(i=0;i<v;i++){
a=0;
for(k=0;k<100000;k++){
b=randni();
b=s[b];
a=a^b;
if(a==511)break;
}
// printf("%d\n",k);
sum+=k;
// if(k<200)
//sum+=1;
}
sum/=v;
printf("%f",sum);
/* for(i=0;i<84;i++)
printf("%d\n",s[i]);*/
return 0;
}
循环一百万次计算期望均值的结果

大概是517次左右
下面是200次就成功的概率

边栏推荐
- Lihongyi, machine learning 7 Conclusion
- Xshell and xftp tutorial
- 行业分析| 快对讲,楼宇对讲
- 关于Pytorch中双向LSTM的输出表示问题
- 科研丨Web of Science检索技巧
- JS基础4
- 功能真花哨,价格真便宜!长安全新SUV真实力到底怎样?
- 【SemiDrive源码分析】【X9芯片启动流程】32 - DisPlay模块分析 - RTOS侧
- 什么是DAPP系统发展与解析理解
- It is safer for individuals to choose which securities company to open an account for buying floor funds
猜你喜欢

day29 js笔记 2021.09.23

Zero foundation self-study SQL course | if function

Wealth management for programmers

Yann Lecun's new paper: the road to building automatic agents

Recommended practice sharing of Zhilian recruitment based on Nebula graph

Redis6 一:Nosql引入、Redis可以解决什么问题?
This Exception was thrown from a job compiled with Burst, which has limited exception support. report errors

数据库系列:有什么办法对数据库的业务表进行无缝升级

day31 js笔记 DOM下 2021.09.26

Summary of spatial temporal time series prediction modeling methods
随机推荐
TiDB v6.0.0 (DMR) :缓存表初试丨TiDB Book Rush
Redis6 一:Nosql引入、Redis可以解决什么问题?
2022 open source software security status report: over 41% of enterprises do not have enough confidence in open source security
使用ssm项目对Mysql8进行访问的时候,出现连接失败和一些错误的解决办法
NFT卡牌链游系统开发dapp搭建技术详情
JS基础3
[practice] 1364- implement a perfect waterfall flow component on the mobile terminal (with source code)
Day39 prototype chain and page fireworks effect 2021.10.13
New listing of operation light 3.0 - a sincere work of self subversion across the times!
零基础自学SQL课程 | IF函数
利用soapUI获取freemarker的ftl文件模板
Machine learning project captcha based on verification code recognition_ Trainer operation practice
When an entity is converted to JSON, the field with null value is lost
day30 js笔记 BOM和DOM 2021.09.24
Gee: mcd64a1 based globfire daily fire data set
Summary of spatial temporal time series prediction modeling methods
拼接String集合中的字符串_基于Stream
day36 js笔记 ECMA6语法 2021.10.09
JS foundation 1-js introduction and operator
[sword finger offer] 49 Ugly number