当前位置:网站首页>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;
}
边栏推荐
- 论文阅读_医疗NLP模型_ EMBERT
- Sophon AutoCV:助力AI工业化生产,实现视觉智能感知
- How can cluster deployment solve the needs of massive video access and large concurrency?
- [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
- Six bad safety habits in the development of enterprise digitalization, each of which is very dangerous!
- U-Net: Convolutional Networks for Biomedical Images Segmentation
- 吳恩達團隊2022機器學習課程,來啦
- QT console printout
- 多线程(一) 进程与线程
- [performance test] full link voltage test
猜你喜欢
Neural network self cognition model
Cmake tutorial Step2 (add Library)
IDC report: Tencent cloud database ranks top 2 in the relational database market!
基于YOLOv3的口罩佩戴检测
EPM related
Unicode processing in response of flash interface
mybash
小林coding的内存管理章节
寻找第k小元素 前k小元素 select_k
Thesis reading_ Chinese NLP_ LTP
随机推荐
How to solve the error "press any to exit" when deploying multiple easycvr on one server?
Sophon CE社区版上线,免费Get轻量易用、高效智能的数据分析工具
Leetcode exercise - 206 Reverse linked list
Action avant ou après l'enregistrement du message teamcenter
2022新版PMP考试有哪些变化?
[performance test] full link voltage test
Daily exercise: a series of dates
To solve the stubborn problem of Lake + warehouse hybrid architecture, xinghuan Technology launched an independent and controllable cloud native Lake warehouse integrated platform
论文阅读_中文NLP_LTP
Redis Foundation
[paddleclas] common commands
图扑软件数字孪生 | 基于 BIM 技术的可视化管理系统
Is it safe to open an account online? What is the general interest rate of securities financing?
南京大学:新时代数字化人才培养方案探讨
寻找第k小元素 前k小元素 select_k
Leetcode daily practice: rotating arrays
mybash
ELK日志分析系统
Data access - entityframework integration
Thesis reading_ Chinese NLP_ LTP