1079. Total Sales of Supply Chain (25)

//1079. Total Sales of Supply Chain (25)
#include<cstdio>
#include<queue>
using namespace std;

#define maxn 100010

struct node
{
  double price;
  int sale;
  vector<int> child;
}tree[maxn];
int head=0,N;
double init_price,r,sum=0;

void level_order(int root)
{
  queue<int> qu;
  qu.push(root);
  tree[root].price = init_price;
  while (!qu.empty())
  {
    int front = qu.front();
    qu.pop();
    if(tree[front].sale != 0)
    {
      sum += tree[front].sale * tree[front].price;
    }
    for(int i=0; i<tree[front].child.size(); i++)
    {
      int child = tree[front].child[i];
      tree[child].price = tree[front].price * (1.0 + r/100.0); //计算出价格
      qu.push(child);
    }
  }
}
int main()
{


  //读书数据
  scanf("%d%lf%lf",&N,&init_price,&r);
  //读入节点
  for(int i=0; i<N; i++)
  {
    int k;
    scanf("%d",&k);
    if(k == 0)
    {
      int x;
      scanf("%d",&x);
      tree[i].sale = x;
    }
    else
    {
      tree[i].sale = 0;
      for(int j=0; j<k; j++)
      {
        int x;
        scanf("%d",&x);
        tree[i].child.push_back(x);
      }
    }
  }
  //层序遍历,并计算出每层的价格
  level_order(head);
  //sale表示叶子节点卖出去的数量
  printf("%.1f",sum);
  return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值