当前位置:网站首页>赛尔号抽奖模拟求期望
赛尔号抽奖模拟求期望
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次就成功的概率

边栏推荐
- JS基础2
- Solve the problem of reading package listsdonebuilding dependency treereading state informationdone
- 网页提示此站点不安全解决方案
- 元宇宙系统的发展与原理介绍
- Docker modifies the user name and password of MySQL
- mysql-. SQL file phishing Online
- Training notice | special training notice on epidemic prevention and security prevention for overseas Chinese funded enterprises, institutions and personnel in 2022
- Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
- Setinterval, setTimeout and requestanimationframe
- Word、PDF、TXT文件实现全文内容检索需要用什么方法?
猜你喜欢

Redis6 1: what problems can be solved by the introduction of NoSQL and redis?

ThreadLocal的简单理解

Web page tips this site is unsafe solution

Wealth management for programmers

远程登录sshd服务

《运营之光3.0》全新上市——跨越时代,自我颠覆的诚意之作!

Jetpack Compose Desktop 桌面版本的打包和发布应用
This Exception was thrown from a job compiled with Burst, which has limited exception support. report errors

阿里三面:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别

Scientific research - web of science retrieval skills
随机推荐
2022 open source software security status report: over 41% of enterprises do not have enough confidence in open source security
Docker modifies the user name and password of MySQL
File的io流与base64
Making and using of static library
合约量化系统开发(搭建讲解)丨合约量化系统开发(源码解析及现成案例)
远程登录sshd服务
This Exception was thrown from a job compiled with Burst, which has limited exception support. 报错
windows 10下载安装mysql5.7
Makefile introduction
JS foundation 4
使用ssm项目对Mysql8进行访问的时候,出现连接失败和一些错误的解决办法
Introduction to GDB
Xshell和Xftp使用教程
Convert the file URL in the browser to a file stream
李宏毅《机器学习》丨7. Conclusion(总结)
选择哪种编程语言,会吸引优秀的人才?
【SemiDrive源码分析】【X9芯片启动流程】32 - DisPlay模块分析 - RTOS侧
Xshell and xftp tutorial
mysql-. SQL file phishing Online
Redis6 一:Nosql引入、Redis可以解决什么问题?