PAT A1079 Total Sales of Supply Chain (25 point(s))

题目

PAT A1079 Total Sales of Supply Chain (25 point(s))_第1张图片
在这里插入图片描述

Code

#include
#include
#include
#include
using namespace std;
const int maxn=100100;
struct node{
double data;
vector child;
}Node[maxn];
int n;
double p,r,ans=0;
void DFS(int index,int depth){
if(Node[index].child.size()==0){// leaf 临界条件
ans+=Node[index].data*pow(1+r, depth);
return;
}
for(int i= 0; i DFS(Node[index].child[i], depth+1);
}
}

int main(){
int k,child;
scanf("%d%lf%lf",&n,&p,&r);
r/=100;
for(int i=0;i scanf("%d",&k);
if(k==0){
scanf("%lf",&Node[i].data);
}else{
for(int j=0;j scanf("%d",&child);
Node[i].child.push_back(child);
}
}

}
DFS(0,0);
printf("%.1f\n",p*ans);
return 0;

}

你可能感兴趣的:(PAT)