L2-020 功夫传人

题目 L2-020 功夫传人

image-5f03eb07

思路分析

代码实现

#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

using ll = long long;

using ull = unsigned long long;

using PII = pair<int,int>;

using Pll = pair<ll,ll>;

int dx[4]= {-1,0,1,0},dy[4]= {0,1,0,-1};

const int inf = 0x3f3f3f3f;

priority_queue<int> pq;

multiset<int> s;

struct People{

	int king=1;

	vector<int> child;

};

vector<People> person;

int n;

double r,z,res=0;

void dfs(int u,double k){

	if(person[u].king!=1){

		k*=person[u].king;

		res+=k;

	}

	for(auto nxt:person[u].child){

		double nxtk=k*(100-r)/100;

		dfs(nxt,nxtk);

	}

}

int main() {

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	cin>>n>>z>>r;

	person.resize(n);

	for(int i=0;i<n;i++){

		int k;cin>>k;

		if(k==0){

			cin>>person[i].king;

		}else{

			while(k--){

				int t;cin>>t;

				person[i].child.push_back(t);

			}

		}

	}

	dfs(0,z);

	cout<<(int)res;

	return 0;

}

同类题型

视频讲解


⬅️ L2-019 悄悄关注 🏠 00-天梯赛 ➡️ L2-021 点赞狂魔