PAT:1079. Total Sales of Supply Chain (25) AC

#include<stdio.h>
#include<math.h>
#include<vector>
using namespace std;
const int MAX=100010;

int DEPest=0;
int root=-1,N;
double P,r,sum=0;

vector<int> child[MAX];        //child[父亲][孩子]  二维数组表示树形结构

double price[MAX];          //记录叶子节点的权值

void DFS(int root,int depth)
{
  if(child[root].size()==0)    //叶子节点开始判断深度
  {
    double p=pow(1+r,1.0*depth)*P;    //【skill】转化为double型,乘以1.0
    /*for(int i=0 ; i<depth ; ++i)
      p*=(1+r);
      */
    sum+=p*price[root];      //总价加上数量乘以单价
    return;
  }
  for(int i=0 ; i<child[root].size() ; ++i)
    DFS(child[root][i],depth+1);
}
int main()
{

  scanf("%d%lf%lf",&N,&P,&r);
  r/=100;              //换算成百分数
  for(int i=0 ; i<N ; ++i)
  {
    int father,tmp;
    scanf("%d",&father);
    if(father!=0)
    {
      for(int j=0 ; j<father ; ++j)
      {
        scanf("%d",&tmp);
        child[i].push_back(tmp);
      }
    }
    else
    {
      scanf("%lf",&price[i]);        //叶子节点权值
    }
  }
  DFS(0,0);
  printf("%.1f",sum);
  return 0;
}
时间: 2024-12-08 09:43:29

PAT:1079. Total Sales of Supply Chain (25) AC的相关文章

PAT Advanced 1079 Total Sales of Supply Chain (25) [DFS,BFS,树的遍历]

题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone involved in moving a product from supplier to customer. Starting from one root supplier, everyone on the chain buys products from one's supplier in a pr

PAT 1079. Total Sales of Supply Chain (25)

1079. Total Sales of Supply Chain (25) A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer. Starting from one root supplier, everyone on the chain buys

1079. Total Sales of Supply Chain (25)

时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer. Starting from one root supplie

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

题意: 输入一个正整数N(<=1e5),表示共有N个结点,接着输入两个浮点数分别表示商品的进货价和每经过一层会增加的价格百分比.接着输入N行每行包括一个非负整数X,如果X为0则表明该结点为叶子结点接着输入一个整数表示该零售商进货的数量,X不为零则接着输入X个正整数表示它的下级经销商是哪些结点.输出所有零售商进货的总价.(结点从0~N-1,0为根节点即供应商) 代码: #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using name

PAT (Advanced Level) 1079. Total Sales of Supply Chain (25)

树的遍历. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<iostream> #include<algorithm> using namespace std

PAT:1090. Highest Price in Supply Chain (25) AC

#include<stdio.h> #include<vector> using namespace std; const int MAX=100010; int DEPest=0,times=0; vector<int> child[MAX]; //child[父亲][孩子] 二维数组表示树形结构 void DFS(int root,int depth) { if(child[root].size()==0) //叶子节点开始判断深度 { if(depth>DE

pat1079. Total Sales of Supply Chain (25)

1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to c

PAT 1079 Total Sales of Supply Chain[比较]

1079 Total Sales of Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer. Starting from one root supplier, everyone on the chain buys

树的遍历——A1079.Total Sales of Supply Chain(25) 与A1090类似

#include <bits/stdc++.h> #include <stdio.h> #include <stdlib.h> #include <queue> using namespace std; const int maxn = 100010; struct node{ double data; vector<int> child; }Node[maxn]; int n; double p,r,ans = 0; void DFS(int