当前位置:网站首页>赛尔号抽奖模拟求期望
赛尔号抽奖模拟求期望
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次就成功的概率
边栏推荐
- 2022中国信通院首届业务与应用安全发展论坛成功召开!
- New listing of operation light 3.0 - a sincere work of self subversion across the times!
- 【sciter】: sciter-fs模块扫描文件API的使用及其注意细节
- This Exception was thrown from a job compiled with Burst, which has limited exception support. report errors
- 远程登录sshd服务
- 使用ssm项目对Mysql8进行访问的时候,出现连接失败和一些错误的解决办法
- Wealth management for programmers
- Oracle 日期格式化异常:无效数字
- GEE:基于 MCD64A1 的 GlobFire 日常火灾数据集
- Zero foundation self-study SQL course | if function
猜你喜欢
培训通知|2022年境外中资企业机构及人员疫情防控和安全防范专题培训通知
Industry analysis - quick intercom, building intercom
一套十万级TPS的IM综合消息系统的架构实践与思考
Everyone can participate in open source! Here comes the most important developer activity in dragon lizard community
day29 js笔记 2021.09.23
This Exception was thrown from a job compiled with Burst, which has limited exception support. report errors
网页提示此站点不安全解决方案
智联招聘基于 Nebula Graph 的推荐实践分享
Oracle 日期格式化异常:无效数字
行业分析| 快对讲,楼宇对讲
随机推荐
实体转JSON时,值为null的字段的丢失问题
合约量化系统开发(搭建讲解)丨合约量化系统开发(源码解析及现成案例)
Which broker is safer and more convenient to open an account for Oriental Fortune mobile stock?
论文阅读 (59):Keyword-Based Diverse Image Retrieval with Variational Multiple Instance Graph
Recommended practice sharing of Zhilian recruitment based on Nebula graph
Word、PDF、TXT文件实现全文内容检索需要用什么方法?
[sciter]: how sciter uses i18 to realize multi language switching of desktop applications and its advantages and disadvantages
JS基础8
零基础自学SQL课程 | IF函数
Create ECS using API shortcut
JS foundation 5
Excel导入导出便捷工具类
String & heap & method area
day37 js笔记 运动函数 2021.10.11
File的io流与base64
行业分析| 快对讲,楼宇对讲
It is safer for individuals to choose which securities company to open an account for buying floor funds
将浏览器中的文件 url转换为File流
[semidrive source code analysis] [x9 chip startup process] 32 - play module analysis - RTOS side
GDB简介