当前位置:网站首页>模拟百囚徒问题
模拟百囚徒问题
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;
}边栏推荐
猜你喜欢

Mask wearing detection based on yolov3

flask接口响应中的中文乱码(unicode)处理

Abnormal recovery of virtual machine Oracle -- Xi Fenfei

What are the requirements for PMP certification? How much is it?

Star Ring Technology launched transwarp Navier, a data element circulation platform, to help enterprises achieve secure data circulation and collaboration under privacy protection

Redis基础

Knowledge points of MySQL (7)

mybash

EPM相关

ISPRS2022/云检测:Cloud detection with boundary nets基于边界网的云检测
随机推荐
毫无章法系列
To solve the problem of "double click PDF file, pop up", please install Evernote program
职场进阶指南:大厂人必看书籍推荐
Star Ring Technology launched transwarp Navier, a data element circulation platform, to help enterprises achieve secure data circulation and collaboration under privacy protection
Is it safe to open an account online? What is the general interest rate of securities financing?
数值计算方法 Chapter8. 常微分方程的数值解
Thesis reading_ Chinese NLP_ LTP
Anaconda中配置PyTorch环境——win10系统(小白包会)
星环科技重磅推出数据要素流通平台Transwarp Navier,助力企业实现隐私保护下的数据安全流通与协作
mybash
Matlab reference
使用QT设计师界面类创建2个界面,通过按键从界面1切换到界面2
Compter le temps d'exécution du programme PHP et définir le temps d'exécution maximum de PHP
Count the running time of PHP program and set the maximum running time of PHP
Sophon Base 3.1 推出MLOps功能,为企业AI能力运营插上翅膀
Teamcenter 消息注册前操作或后操作
Eliminate the writing of 'if () else{}'
QT console printout
寻找第k小元素 前k小元素 select_k
Zabbix
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