当前位置:网站首页>模拟百囚徒问题
模拟百囚徒问题
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;
}边栏推荐
- MATLAB查阅
- Redis基础
- ISPRS2022/雲檢測:Cloud detection with boundary nets基於邊界網的雲檢測
- Thesis reading_ Medical NLP model_ EMBERT
- Cmake tutorial step1 (basic starting point)
- 2022新版PMP考试有哪些变化?
- ISPRS2022/云检测:Cloud detection with boundary nets基于边界网的云检测
- 检查命名空间和类
- mybash
- Vulnerability recurrence - 48. Command injection in airflow DAG (cve-2020-11978)
猜你喜欢

Compter le temps d'exécution du programme PHP et définir le temps d'exécution maximum de PHP

2022新版PMP考试有哪些变化?

星环科技重磅推出数据要素流通平台Transwarp Navier,助力企业实现隐私保护下的数据安全流通与协作

EPM related

Configure pytorch environment in Anaconda - win10 system (small white packet meeting)

Six bad safety habits in the development of enterprise digitalization, each of which is very dangerous!

Thesis reading_ Medical NLP model_ EMBERT

Vulnerability recurrence - 48. Command injection in airflow DAG (cve-2020-11978)

Sophon CE社区版上线,免费Get轻量易用、高效智能的数据分析工具

星环科技数据安全管理平台 Defensor重磅发布
随机推荐
Daily exercise: a series of dates
读libco保存恢复现场汇编代码
多线程(一) 进程与线程
ELK日志分析系统
Sentinel-流量防卫兵
Simple query cost estimation
Easynmon Usage Summary
leetcode每日一题:字符串中的第一个唯一字符
Thesis reading_ Chinese NLP_ LTP
Mask wearing detection based on yolov3
How to save the trained neural network model (pytorch version)
热通孔的有效放置如何改善PCB设计中的热管理?
外盘黄金哪个平台正规安全,怎么辨别?
Sophon AutoCV:助力AI工业化生产,实现视觉智能感知
How to modify MySQL fields as self growing fields
为什么阳历中平年二月是28天
Is it safe to open an account online? What is the general interest rate of securities financing?
使用QT遍历Json文档及搜索子对象
[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
如何修改mysql字段为自增长字段
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