【PAT甲级】1079. Total Sales of Supply Chain (25)
来源:互联网 发布:卡在windows启动界面 编辑:程序博客网 时间:2024/05/01 12:51
#include <stdio.h>#include <iostream>#include <vector>#include <stack>#include <math.h>using namespace std;int main() { int n; double p, r; cin >> n >> p >> r; vector<int> *v = new vector<int>[n]; int *count = new int[n]; for (int i = 0; i < n; i++) { int num, tmp; cin >> num; if (num > 0) { for(int j = 0; j < num; j++) { cin >> tmp; v[i].push_back(tmp); } } else { cin >> count[i]; } } stack<int> tree; stack<int> layer; tree.push(0); layer.push(0); double sum = 0.0; while (tree.size()) { int tmp = tree.top(); tree.pop(); int l = layer.top(); layer.pop(); if (v[tmp].empty()) { sum += p * pow((1 + r/100), l) * count[tmp]; } for (int i = 0; i < v[tmp].size(); i++) { tree.push(v[tmp][i]); layer.push(l + 1); } } printf("%.1lf\n", sum); return 0;}
阅读全文
0 0
- 1079. Total Sales of Supply Chain (25)PAT甲级
- PAT甲级练习1079. Total Sales of Supply Chain (25)
- 【PAT甲级】1079. Total Sales of Supply Chain (25)
- PAT 甲级 1079. Total Sales of Supply Chain (25)
- 【PAT】1079. Total Sales of Supply Chain
- PAT--1079. Total Sales of Supply Chain
- PAT 1079. Total Sales of Supply Chain (25)
- PAT (Advanced) 1079. Total Sales of Supply Chain (25)
- PAT Advanced Level 1079. Total Sales of Supply Chain (25)
- PAT A 1079. Total Sales of Supply Chain (25)
- PAT 1079. Total Sales of Supply Chain (25)
- PAT 1079. Total Sales of Supply Chain (25)
- PAT 1079. Total Sales of Supply Chain (25)
- 【PAT】1079. Total Sales of Supply Chain (25)
- PAT-A-1079. Total Sales of Supply Chain (25)
- 【PAT】【Advanced Level】1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- XZ_iOS之函数式编程和链式编程
- Java 错误:找不到或无法加载主类(源文件中含有包名 package)
- Vue.js 组件和组件通信
- 生产消费中的死锁问题
- 判断二叉树是否为完全二叉树
- 【PAT甲级】1079. Total Sales of Supply Chain (25)
- 7.30小记
- bash: 一键安装Ananconda & 一键设置conda永久镜像
- hdu 6052单调栈 双指针
- CSS深入理解(1)margin
- DPDK 内存管理(二)(rte_mempool 内存管理)
- 模拟实现atoi函数
- android 城市选择
- Numpy基础:数组和矢量计算