当前位置:网站首页>Simulate the hundred prisoner problem
Simulate the hundred prisoner problem
2022-07-05 18:03:00 【Memory condensation】
#include <iostream>
#include <time.h>
using namespace std;
const int N = 100;
int dfs(int a[], int x, int vis[]) {
if (vis[a[x]]) {
return 0;
}
vis[a[x]] = 1;
return dfs(a, a[a[x]], vis) + 1;
}
int main() {
srand(time(0));
int cnt = 0, T = 100000;
for (int round = 0; round < T; round++) {
int a[128] = {0};
for (int i = 1; i <= N; i++) {
a[i] = i;
}
for (int i = N; i > 1; i--) {
int r = 1 + rand() % i;
int t = a[i];
a[i] = a[r];
a[r] = t;
}
int vis[128] = {0};
for (int i = 1; i <= N; i++) {
if (dfs(a, i, vis) > (N >> 1)) {
cnt++;
break;
}
}
}
cout << 1.0 * cnt / T;
return 0;
}边栏推荐
- RSE2020/云检测:基于弱监督深度学习的高分辨率遥感图像精确云检测
- Configure pytorch environment in Anaconda - win10 system (small white packet meeting)
- [TestLink] testlink1.9.18 solutions to common problems
- PMP认证需具备哪些条件啊?费用多少啊?
- 【PaddleClas】常用命令
- Redis基础
- Ten top automation and orchestration tools
- 使用QT遍历Json文档及搜索子对象
- MATLAB查阅
- 访问数据库使用redis作为mysql的缓存(redis和mysql结合)
猜你喜欢

Sophon autocv: help AI industrial production and realize visual intelligent perception

星环科技数据安全管理平台 Defensor重磅发布

GFS distributed file system

ISPRS2022/云检测:Cloud detection with boundary nets基于边界网的云检测

Leetcode daily question: the first unique character in the string
![最大人工岛[如何让一个连通分量的所有节点都记录总节点数?+给连通分量编号]](/img/8b/a60fc36115580f018445e4c2a28a9d.png)
最大人工岛[如何让一个连通分量的所有节点都记录总节点数?+给连通分量编号]

Zabbix

flask接口响应中的中文乱码(unicode)处理

Sophon Base 3.1 推出MLOps功能,为企业AI能力运营插上翅膀

Isprs2022 / Cloud Detection: Cloud Detection with Boundary nets Boundary Networks Based Cloud Detection
随机推荐
图片数据不够?我做了一个免费的图像增强软件
Why is all (()) true and any (()) false?
Read libco save and restore the on-site assembly code
How to solve the error "press any to exit" when deploying multiple easycvr on one server?
Daily exercise: a series of dates
[JMeter] advanced writing method of JMeter script: all variables, parameters (parameters can be configured by Jenkins), functions, etc. in the interface automation script realize the complete business
破解湖+仓混合架构顽疾,星环科技推出自主可控云原生湖仓一体平台
EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
Cmake tutorial Step3 (requirements for adding libraries)
EPM相关
RSE2020/云检测:基于弱监督深度学习的高分辨率遥感图像精确云检测
How can cluster deployment solve the needs of massive video access and large concurrency?
FCN: Fully Convolutional Networks for Semantic Segmentation
Sophon Base 3.1 推出MLOps功能,为企业AI能力运营插上翅膀
Sophon autocv: help AI industrial production and realize visual intelligent perception
Thesis reading_ Medical NLP model_ EMBERT
Operation before or after Teamcenter message registration
Eliminate the writing of 'if () else{}'
"Xiaodeng in operation and maintenance" is a single sign on solution for cloud applications
Elk log analysis system
https://www.bilibili.com/video/BV1kt4y1t75F?p=1&share_medium=android&share_plat=android&share_session_id=55f1ff0e-fda4-43be-8c5a-112768033498&share_source=QQ&share_tag=s_i×tamp=1656936860&unique_k=Ru3JMdE&vd_source=78c5a56b2b804449168dbad7346576d9