当前位置:网站首页>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;
}
边栏推荐
- Sophon kg upgrade 3.1: break down barriers between data and liberate enterprise productivity
- Size_t 是无符号的
- Generate classes from XML schema
- [TestLink] testlink1.9.18 solutions to common problems
- LeetCode 练习——206. 反转链表
- Please tell me why some tables can find data by writing SQL, but they can't be found in the data map, and the table structure can't be found
- Operation before or after Teamcenter message registration
- OpenShift常用管理命令杂记
- matlab内建函数怎么不同颜色,matlab分段函数不同颜色绘图
- EPM related
猜你喜欢
Sophon autocv: help AI industrial production and realize visual intelligent perception
Leetcode exercise - 206 Reverse linked list
Leetcode daily question: merge two ordered arrays
Find the first k small element select_ k
Isprs2022 / Cloud Detection: Cloud Detection with Boundary nets Boundary Networks Based Cloud Detection
Sophon KG升级3.1:打破数据间壁垒,解放企业生产力
论文阅读_中文NLP_LTP
南京大学:新时代数字化人才培养方案探讨
Cmake tutorial step1 (basic starting point)
吳恩達團隊2022機器學習課程,來啦
随机推荐
Leetcode daily practice: rotating arrays
Matlab reference
MATLAB中print函数使用
小林coding的内存管理章节
What are the requirements for PMP certification? How much is it?
Access the database and use redis as the cache of MySQL (a combination of redis and MySQL)
Why is all (()) true and any (()) false?
论文阅读_医疗NLP模型_ EMBERT
Numerical calculation method chapter8 Numerical solutions of ordinary differential equations
钉钉开放平台小程序API的缓存接口都有哪些内容?
Mask wearing detection based on yolov3
[performance test] full link voltage test
Le cours d'apprentissage de la machine 2022 de l'équipe Wunda arrive.
nano的CAN通信
EPM相关
华夏基金:基金行业数字化转型实践成果分享
含重复元素取不重复子集[如何取子集?如何去重?]
Why is February 28 in the Gregorian calendar
图像分类,看我就够啦!
图片数据不够?我做了一个免费的图像增强软件