L2-020 功夫传人

...祖师爷也可能是得道者,这合理吗?(坑)

#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> a;
map<int, double> dd;
double tota = 0;
int n;//人数
double z, r;//祖师爷功力 衰减百分比
double sj;
void dfs(int k, double size) {//size是师父传给他的功力
	if (dd[k]) {
		tota += size * dd[k];
	}
	else {
		for (int i = 0; i < a[k].size(); i++) {
			dfs(a[k][i], size * sj);
		}
	}
}
int main() {
	cin >> n >> z >> r;
	sj=(100 - r) / 100;
	a.resize(n + 10);
	for (int i = 0; i < n; i++) {
		int t;
		double gl;
		cin >> t;
		if (t == 0) { //第i号得道了 i是从0开始的
			cin >> gl;
			dd[i] = gl;
			continue;
		}
		for (int j = 0; j < t; j++) { //遍历徒弟们
			int tno;//徒弟编号
			cin >> tno;
			a[i].push_back(tno);
		}
	}
	dfs(0, z);
	int d = (int)tota;
	cout << d << endl;
	return 0;
}
posted @ 2024-03-18 16:53  YuKiCheng  阅读(10)  评论(0编辑  收藏  举报