北邮oj寻找宝藏

博主起初不明白示例为何是0.25,通过阅读https://blog.youkuaiyun.com/miliu0408/article/details/86762919这篇文章,知晓了1/4(即0.25)的由来。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述
在这里插入图片描述
我开始怎么也没想到示例怎么是0.25的,看了https://blog.youkuaiyun.com/miliu0408/article/details/86762919
这篇大神的文章,我才知道1/4是怎么来的。
在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
#define maxn 1005
struct node{
	int father;//父节点 
	vector<int> son;//儿子节点 
};
node tree[maxn];
int main(){
	int N,M,L;
	int f,s; 
	scanf("%d %d %d",&N,&M,&L);
	for(int i=0;i<maxn;i++){
		tree[i].son.clear();
		tree[i].father = -1;
	}
	for(int i=0;i<M;i++){
		scanf("%d %d",&f,&s);
		tree[f].son.push_back(s);
		tree[s].father = f;
	}
	vector<int> Fac;//存入宝藏节点的所有祖宗节点 
	Fac.clear();
	while(tree[L].father!=-1){
		Fac.push_back(tree[L].father);
		L = tree[L].father;
	}
	double fm = 1.0;//分母 
	for(int i=0;i<Fac.size();i++){
		fm = fm*tree[Fac[i]].son.size();//将所有祖宗节点的可能路径方向(即儿子节点的个数)乘起来 
	}
	double ans = 1.0/fm;
	printf("%.6f",ans);
	return 0;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值