1079. Total Sales of Supply Chain (25)
来源:互联网 发布:单片机经典项目 编辑:程序博客网 时间:2024/06/17 12:01
//1079. Total Sales of Supply Chain (25)#include<cstdio>#include<queue>using namespace std;#define maxn 100010struct 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
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 用shell脚本来判断Apache是否开启
- tensorflow读取SVHN数据集转为TFrecords格式
- Linux下安装mysql
- list的四种遍历方式,遍历list集合
- 关于Xcode编译性能优化的研究工作总结
- 1079. Total Sales of Supply Chain (25)
- ABI与API的区别
- Codevs 3955 最长严格上升子序列(加强版)
- [leetcode:python]53.Maximum Subarray
- Codeforces 801C 二分法
- 处理音频--pyaudio
- 洛谷 P1993 小 K 的农场
- C语言指针
- JSP乱码及编码解码问题