【1079】Total Sales of Supply Chain (25 分)

简介: 【1079】Total Sales of Supply Chain (25 分)【1079】Total Sales of Supply Chain (25 分)
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>  
#include<map>
#include<vector>
#include<queue> 
using namespace std;  
//key:DFS递归  树结点存储
const int maxn=100010;
struct node{
  double data;  //数据域(货物量)
  vector<int> child;  //指针域
}Node[maxn];  //存放树
int n;
double p,r,ans=0;  //ans为叶结点货物的价格之和
void DFS(int index,int depth){  //注意!根结点的深度设为0!
  if(Node[index].child.size()==0){ //到达叶结点
    ans+= Node[index].data*pow(1+r,depth);  //累加叶结点货物的价格
    return ;
  }
  for(int i=0;i<Node[index].child.size();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<n;i++){
    scanf("%d",&k);
    if(k==0){    //叶结点标志
      scanf("%lf",&Node[i].data);   //叶结点货物量
    }else{
      for(int j=0;j<k;j++){
        scanf("%d",&child);
        Node[i].child.push_back(child);  //child为结点i的子结点
      }
    }
  }
  DFS(0,0);  //DFS入口
  printf("%.1f\n",p*ans);  //输出结果
  system("pause");
    return 0;   
}
相关文章
|
存储 供应链 C++
【PAT甲级 - C++题解】1079 Total Sales of Supply Chain
【PAT甲级 - C++题解】1079 Total Sales of Supply Chain
87 0
|
存储 供应链 C++
【PAT甲级 - C++题解】1106 Lowest Price in Supply Chain
【PAT甲级 - C++题解】1106 Lowest Price in Supply Chain
75 0
PAT (Advanced Level) Practice - 1119 Pre- and Post-order Traversals(30 分)
PAT (Advanced Level) Practice - 1119 Pre- and Post-order Traversals(30 分)
121 0
PAT (Advanced Level) Practice - 1119 Pre- and Post-order Traversals(30 分)
错误消息sales area is not assigned for the header product
When I try to download customer material info record from ERP, I meet with this error message in tcode SMW01:
错误消息sales area is not assigned for the header product
|
供应链
PAT (Advanced Level) Practice - 1079 Total Sales of Supply Chain(25 分)
PAT (Advanced Level) Practice - 1079 Total Sales of Supply Chain(25 分)
138 0
PAT (Advanced Level) Practice - 1072 Gas Station(30 分)
PAT (Advanced Level) Practice - 1072 Gas Station(30 分)
125 0
PAT (Advanced Level) Practice - 1146 Topological Order(25 分)
PAT (Advanced Level) Practice - 1146 Topological Order(25 分)
86 0
PAT (Advanced Level) Practice - 1145 Hashing - Average Search Time(25 分)
PAT (Advanced Level) Practice - 1145 Hashing - Average Search Time(25 分)
117 0
PAT (Advanced Level) Practice - 1030 Travel Plan(30 分)
PAT (Advanced Level) Practice - 1030 Travel Plan(30 分)
107 0
PAT (Advanced Level) Practice - 1012 The Best Rank(25 分)
PAT (Advanced Level) Practice - 1012 The Best Rank(25 分)
116 0