1079. Total Sales of Supply Chain (25)
来源:互联网 发布:java中lambda表达式 编辑:程序博客网 时间:2024/05/16 07:22
还是挺水的这题
本来还以为要递归
结果递归都不用
贴AC代码:
#include <bits/stdc++.h>using namespace std;int main(void){ int n; double root, rate, sum = 0; cin >> n >> root >> rate; int i, j; vector<int> pre(n);//本来写好了代码,发现和示例输出不一样,仔细查看示例,发现我的算法存在漏洞 queue<int> notcal;//漏洞就是,你在算某个价格的时候,是用它前面的价格乘以增长率,但是他前面的价格可能是0,没有更新过 vector<double> arr(n); vector<bool> test(n, false); vector<int> num(n); arr[0] = root; for (i = 0; i < n; i++) { int temp; cin >> temp; if (arr[i] == 0) { for (j = 0; j < temp; j++)//所以我们先记下来,然后到时候再处理它 { int index; cin >> index; pre[index] = i; notcal.push(index); } } else { for (j = 0; j < temp; j++) { int index; cin >> index; arr[index] = arr[i] * (1.0 + rate/100); } } if (temp == 0) { test[i] = true; cin >> num[i]; } } while (!notcal.empty())//不断循环,总能让所有的价格全部算出来 { int index = notcal.front(); int temp = pre[index]; if (arr[temp] == 0) { notcal.pop(); notcal.push(index); } else { arr[index] = arr[temp] * (1.0 + rate/100); notcal.pop(); } } for (i = 0; i < n; i++) { if (test[i]) sum += arr[i] * num[i]; } printf("%.1lf", 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)
- HTML特殊字符编码对照表
- java 2 笔记
- 82岁“极客”老人借阿里云写族谱:想去云栖大会看马云!
- 通达OA麦枫破解版管理员如何进行软件安装和初始化?
- ls命令详解
- 1079. Total Sales of Supply Chain (25)
- 一篇文章,教你学会Git
- Spring boot 报错:Cannot determine embedded database driver class for database type NONE
- 配置MySQL GTID 主从复制
- CentOS6.5 配置安装并配置rsync
- TCP/IP学习笔记(13)-TCP坚持定时器,TCP保活定时器
- CROSSTAB 的使用
- linuxLVM扩容
- Java学习路线图