AcWing 1565. 供应链总销售额
原题链接
简单
作者:
xxxxuu
,
2021-08-22 16:43:35
,
所有人可见
,
阅读 268
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
const int N=100010;
int n; //总结点数
double p,r; //根结点价格 溢价百分比
double ans=0.0; //总销售额
struct node{
double data; //叶子结点的销售量 结果为小数所以定义为double型
vector<int> child;
}tree[N];
void dfs(int root,int depth){
if(tree[root].child.size()==0){ //当前结点为叶子结点
ans+=tree[root].data*pow(1+r,depth);
}
for(int i=0;i<tree[root].child.size();i++){
dfs(tree[root].child[i],depth+1);
}
}
int main(){
cin>>n>>p>>r;
r=r/100.0;
for(int i=0;i<n;i++){
int k;
cin>>k;
if(k==0){ //若为叶子结点
int cnt;
cin>>cnt;
tree[i].data=cnt;
}
else{
while(k--){
int child;
cin>>child;
tree[i].child.push_back(child);
}
}
}
dfs(0,0);
printf("%0.1f\n",p*ans);
return 0;
}