当前位置:网站首页>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 CE Community Edition is online, and free get is a lightweight, easy-to-use, efficient and intelligent data analysis tool
- Elk log analysis system
- 访问数据库使用redis作为mysql的缓存(redis和mysql结合)
- PMP认证需具备哪些条件啊?费用多少啊?
- 寻找第k小元素 前k小元素 select_k
- [BeanShell] there are many ways to write data locally
- Operation before or after Teamcenter message registration
- leetcode每日一练:旋转数组
- Sophon KG升级3.1:打破数据间壁垒,解放企业生产力
- 论文阅读_中文NLP_LTP
猜你喜欢

Leetcode exercise - 206 Reverse linked list

Redis Foundation

Isprs2022 / Cloud Detection: Cloud Detection with Boundary nets Boundary Networks Based Cloud Detection

隐私计算助力数据的安全流通与共享

Sophon base 3.1 launched mlops function to provide wings for the operation of enterprise AI capabilities

“12306” 的架构到底有多牛逼?

神经网络自我认知模型

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

Anaconda中配置PyTorch环境——win10系统(小白包会)

Sophon autocv: help AI industrial production and realize visual intelligent perception
随机推荐
mybash
Interpretation: how to deal with the current security problems faced by the Internet of things?
Xiaobai getting started with NAS - quick building private cloud tutorial series (I) [easy to understand]
flask接口响应中的中文乱码(unicode)处理
Sophon kg upgrade 3.1: break down barriers between data and liberate enterprise productivity
The comprehensive competitiveness of Huawei cloud native containers ranks first in China!
较文心损失一点点性能提升很多
EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
Matlab built-in function how different colors, matlab subsection function different colors drawing
nacos -分布式事务-Seata** linux安装jdk ,mysql5.7启动nacos配置ideal 调用接口配合 (保姆级细节教程)
EPM related
检查命名空间和类
Image classification, just look at me!
吴恩达团队2022机器学习课程,来啦
星环科技数据安全管理平台 Defensor重磅发布
Clickhouse (03) how to install and deploy Clickhouse
Privacy computing helps secure data circulation and sharing
Career advancement Guide: recommended books for people in big factories
[BeanShell] there are many ways to write data locally
毫无章法系列
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