1079. Total Sales of Supply Chain (25)
来源:互联网 发布:淘宝中国造 编辑:程序博客网 时间:2024/06/05 06:52
算出所有节点所处的层数s,然后按P*(1+r%)^s计算即可
#include <iostream>#include <vector>#include<cmath>#pragma warning(disable:4996)using namespace std;struct node { vector<int> son; int lev;//层数 node() { lev = 0; } int x;//个数};vector<node> all;int N;double P, r;void bfs(int index){ for (auto &x : all[index].son) { all[x].lev = all[index].lev + 1; bfs(x); }}int main() { cin >> N >> P >> r; r = r / 100 + 1; all.resize(N); for (int t = 0;t < N;t++)//存储输入 { int temp; cin >> temp; if (temp == 0) cin >> all[t].x; while (temp--) { int te; cin >> te; all[t].son.push_back(te); } } bfs(0);//计算各个节点的层数 double sum = 0; for (auto x : all) if (x.son.empty()) sum += P*pow(r, x.lev)*x.x; printf("%.1f\n", sum);}
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)
- Android环境变量配置
- Android 画图之修图
- Android中Robolectric的使用
- 从C到C++的升级之函数升级
- iOS 检测网络状态
- 1079. Total Sales of Supply Chain (25)
- MySQL--数据备份还原以及主从复制
- android搜索热词(热门标签)流式布局的实现
- 三、qml调用Q_INVOKABLE方法
- java 利用jsp打印html页面
- Android aidl问题汇总
- ES6 常用API详解
- USACO 2010 Feb Silver 3.Chocolate Eating 吃巧克力
- Not found org.springframework.http.converter.json.MappingJacksonHttpMessageConve配置文件中报错