[PAT] Grade 1079 Total Sales of Supply Chain (25 points)

Meaning of the questions:

Enter a positive integer N (<= 1e5), represents a total of N nodes, then enter the two floating point numbers represent the percentage of the price and the purchase price of the commodity through each layer will increase. Then enter N lines comprising a non-negative integer X, if X is 0 indicates that the node is a leaf node and then enter the number of the retailer stock integer, X is not zero and then enter the positive integer X it's what lower-level dealers node. Total output for all retail purchase. (From node 0 ~ N-1,0 supplier i.e. a root node)

Code:

#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[100007],lv[100007],ans[100007];
vector<int>v[100007];
void dfs(int x){
for(int it=0;it<v[x].size();++it){
lv[v[x][it]]=lv[x]+1;
dfs(v[x][it]);
}
return ;
}
int main(){
//ios::sync_with_stdio(false);
//cin.tie(NULL);
//cout.tie(NULL);
int n;
cin>>n;
double p,r;
cin>>p>>r;
int cnt=0;
for(int i=0;i<n;++i){
int x,num;
cin>>x;
if(!x){
cin>>num;
a[i]=num;
ans[++cnt]=i;
}
for(int j=1;j<=x;++j){
cin>>num;
v[i].push_back(num);
}
}
dfs(0);
double sum=0;
for(int i=1;i<=cnt;++i){
double tamp=1.0*a[ans[i]]*p*pow(1.0+0.01*r,lv[ans[i]]);
sum+=tamp;
}
printf("%.1lf",sum);
return 0;
}

Guess you like

Origin www.cnblogs.com/ldudxy/p/11823045.html