L2-020 功夫传人

#include 
#include 
using namespace std;
//10 18.0 1.00
//3 2 3 5
//1 9
//1 4
//1 7
//0 7
//2 6 1
//1 8
//0 9
//0 4
//0 3
#define M 100000
double arr[M + 5];
vector vis[M + 5];
vector ans;
//当前处理的是第l个人的徒弟
void fun(double r, int l) {
	if (!vis[l][0]) {
		ans.push_back(arr[l] * vis[l][1]);
		return;
	}
	for (int i = 1; i < vis[l].size(); i++) {
		arr[vis[l][i]] = arr[l] * (1 - r / 100);
		fun(r, vis[l][i]);
	}
	return;
}
int main() {
	int n, k;
	double r;
	cin >> n >> arr[0] >> r;
	for (int i = 0; i < n; i++) {
		cin >> k;
		vis[i].push_back(k);
		int a;
		if (!k) {
			cin >> a;
			vis[i].push_back(a);
			continue;
		}
		for (int j = 0; j < k; j++) {
			cin >> a;
			vis[i].push_back(a);
		}
	}
	fun(r, 0);
	double sum = 0;
	for (auto x : ans) {
		sum += x;
	}
	printf("%d", (int)sum);
	return 0;
}

你可能感兴趣的:(算法题,算法,数据结构)