当前位置:网站首页>模拟百囚徒问题
模拟百囚徒问题
2022-07-05 17:50:00 【忆灬凝】
#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;
}
边栏推荐
- 南京大学:新时代数字化人才培养方案探讨
- Disorganized series
- Sophon KG升级3.1:打破数据间壁垒,解放企业生产力
- EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
- 2022 information system management engineer examination outline
- [TestLink] testlink1.9.18 solutions to common problems
- LeetCode每日一题:合并两个有序数组
- 如何修改mysql字段为自增长字段
- GIMP 2.10教程「建议收藏」
- IDC report: Tencent cloud database ranks top 2 in the relational database market!
猜你喜欢
Leetcode daily question: the first unique character in the string
Sophon CE社区版上线,免费Get轻量易用、高效智能的数据分析工具
Oracle recovery tools -- Oracle database recovery tool
破解湖+仓混合架构顽疾,星环科技推出自主可控云原生湖仓一体平台
企业数字化发展中的六个安全陋习,每一个都很危险!
Star ring technology data security management platform defender heavy release
GFS分布式文件系统
职场进阶指南:大厂人必看书籍推荐
星环科技重磅推出数据要素流通平台Transwarp Navier,助力企业实现隐私保护下的数据安全流通与协作
Mongodb (quick start) (I)
随机推荐
VC编程入门浅谈「建议收藏」
Cmake tutorial Step4 (installation and testing)
Accuracy of BigDecimal Division
Sentinel flow guard
数值计算方法 Chapter8. 常微分方程的数值解
Seven Devops practices to improve application performance
Clickhouse (03) how to install and deploy Clickhouse
ELK日志分析系统
Leetcode daily question: merge two ordered arrays
深拷贝与浅拷贝【面试题3】
从XML架构生成类
ISPRS2020/云检测:Transferring deep learning models for cloud detection between Landsat-8 and Proba-V
Sentinel-流量防卫兵
MATLAB查阅
Career advancement Guide: recommended books for people in big factories
使用QT设计师界面类创建2个界面,通过按键从界面1切换到界面2
"Xiaodeng in operation and maintenance" is a single sign on solution for cloud applications
Binder开辟线程数过多导致主线程ANR异常
ISPRS2022/云检测:Cloud detection with boundary nets基于边界网的云检测
flask接口响应中的中文乱码(unicode)处理