1079. Total Sales of Supply Chain 解析
来源:互联网 发布:十代思域18寸轮毂数据 编辑:程序博客网 时间:2024/05/20 20:03
还是老样子的供应商问题,这次是给出了零售商手里有多少手机,全部卖出能卖多少钱。
提前把转手n次后的价格算出来,不然容易超时。
开始以为层数不会太大。。结果还是接近10^5的....
……………………更新线…………………………
用float的同学需要吧float改成double才行。不是精度不够就是float爆了
#include <iostream>#include <vector>#include <queue>#define MAX 100010using namespace std;struct Node{int amount;int level;vector <int> c;Node() { amount = 1; level = 0; }};Node t[MAX];int n;double p, r;double sum = 0;double pSerch[MAX];vector <int> ThisAns;void DFS(int u) {if (t[u].c.size() == 0) {double tp = pSerch[ThisAns.size()];/*for (int i = 0; i < ThisAns.size(); i++) {tp *= (1 + r / 100);}*/sum += (tp * t[u].amount);return;}ThisAns.push_back(u);for (int i = 0; i < t[u].c.size(); i++) {DFS(t[u].c[i]);}ThisAns.pop_back();}void LevelOrder(int st) {queue <int> q;q.push(st);while (!q.empty()) {int top = q.front();q.pop();if (t[top].c.size() == 0) {sum += (pSerch[t[top].level] * t[top].amount);}else {for (int i = 0; i < t[top].c.size(); i++) {q.push(t[top].c[i]);t[t[top].c[i]].level = t[top].level + 1;}}}}int main() {cin >> n >> p >> r;r = 1 + r / 100;double tp = p;for (int i = 0; i < MAX; i++) {pSerch[i] = tp;tp *= r;}int cNum, cNo;for (int i = 0; i < n; i++) {scanf("%d", &cNum);if (cNum == 0) {scanf("%d", &t[i].amount);}else {for (int j = 0; j < cNum; j++) {scanf("%d", &cNo);t[i].c.push_back(cNo);}}}DFS(0);printf("%.01lf\n", sum);return 0;}
0 0
- 1079. Total Sales of Supply Chain 解析
- 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
- 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
- 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)
- easy ui 之layout布局 用法小结(1)
- 数据段、代码段、堆栈段、内存、堆、堆栈、CPU寄存器
- hiho ! 1039 : 字符消除
- CentOS设置静态IP
- 网络编程三要素整理
- 1079. Total Sales of Supply Chain 解析
- 搭建 Asp.net 云服务器
- 剑指offer 24. 二叉搜索树的后序遍历序列
- Enum(枚举类型)的基本应用
- Linux系统中SHELL命令或脚本中关于$理解
- IGN评史上最佳100 RPG
- 2017/5/9
- redis 安装以及phpredis拓展安装
- ajax访问后台,数据放到map中,map明明有值, 前台获取的为null