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

边栏推荐
- 时间戳和date转换「建议收藏」
- day30 js笔记 BOM和DOM 2021.09.24
- JS foundation 1-js introduction and operator
- Day39 prototype chain and page fireworks effect 2021.10.13
- QML控件类型:TabBar
- JS基础4
- Xshell和Xftp使用教程
- This Exception was thrown from a job compiled with Burst, which has limited exception support. report errors
- Mysql使用max函数查询不到最大值
- Introduction to GDB
猜你喜欢

QML control type: tabbar

js中this的默认指向及如何修改指向 2021.11.09

js中的class类模式及语法 2021.11.10

Jetpack Compose Desktop 桌面版本的打包和发布应用

day31 js笔记 DOM下 2021.09.26

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

智联招聘基于 Nebula Graph 的推荐实践分享

Solve the problem of reading package listsdonebuilding dependency treereading state informationdone

动态库(共享库)的制作和使用

QML控件类型:TabBar
随机推荐
Redis6 一:Nosql引入、Redis可以解决什么问题?
Analyze whether there is duplicate data in the list and repeat it several times
Lihongyi, machine learning 7 Conclusion
阿里三面:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
It is safer for individuals to choose which securities company to open an account for buying floor funds
使用API快捷创建ECS
JS foundation 3
毕业季,给初入社会的你一些建议
买股票在中金证券经理的开户二维码上开户安全吗?求大神赐教
Training notice | special training notice on epidemic prevention and security prevention for overseas Chinese funded enterprises, institutions and personnel in 2022
Makefile简介
零基础自学SQL课程 | IF函数
2022中国信通院首届业务与应用安全发展论坛成功召开!
第2章 还记得点、线、面吗(二)
拼接String集合中的字符串_基于Stream
Redis6 1: what problems can be solved by the introduction of NoSQL and redis?
mysql-.sql文件钓鱼上线
MytipartFile与File的相互转换
[sciter]:sciter如何使用i18实现桌面应用多语言切换及其利弊
JS基础4