1079. Total Sales of Supply Chain (25)
2015-11-24 18:26
609 查看
1.使用数的结构存储供应商和零售商
2.采用层次遍历(BFS)进行遍历
3.需要使用double进行存储,一开始发现下面几个耗时大的测试点不通过,所以考虑是精度不够或者溢出的原因,于是改为double类型,然后就通过了
AC代码:
2.采用层次遍历(BFS)进行遍历
3.需要使用double进行存储,一开始发现下面几个耗时大的测试点不通过,所以考虑是精度不够或者溢出的原因,于是改为double类型,然后就通过了
AC代码:
//#include<string> //#include <iomanip> //#include<stack> //#include<unordered_set> //#include <sstream> //#include "func.h" //#include <list> #include<unordered_map> #include<set> #include<queue> #include<map> #include<vector> #include <algorithm> #include<stdio.h> #include<iostream> #include<string> #include<memory.h> #include<limits.h> #include<stack> using namespace std; struct Node{ vector<int> list; bool isRetailer; int productCount; Node() :list(0), isRetailer(false), productCount(0){}; }; int main(void) { int n; double rootPrice, higher;//需要使用double cin >> n >> rootPrice >> higher; vector<Node> chain(n); for (int i = 0; i < n; i++) { int tmp; cin >> tmp; if (tmp == 0) {//零售商 chain[i].isRetailer = true; cin >> chain[i].productCount; } else {//供应商 for (int j = 0; j < tmp; j++) {//输入下级供应商 int nextLevel; cin >> nextLevel; chain[i].list.push_back(nextLevel); } } } queue<int> q; q.push(0); int count1 = 1, count2 = 0; double price = rootPrice; double totalSales = 0; //进行层次遍历 while (!q.empty()) { for (int i = 0; i < count1; i++) { int head = q.front(); q.pop(); if (chain[head].isRetailer) totalSales += chain[head].productCount*price; else { for (int j = 0; j < chain[head].list.size(); j++) { q.push(chain[head].list[j]); count2++; } } } count1 = count2; count2 = 0; price *= (1 + higher / 100.0); } printf("%.1lf\n", totalSales); return 0; }
相关文章推荐
- [转] Bound Service的三种方式(Binder、 Messenger、 AIDL)
- 论垃圾邮件危害性及U-Mail邮件系统必杀技
- 论垃圾邮件危害性及U-Mail邮件系统必杀技
- 论垃圾邮件危害性及U-Mail邮件系统必杀技
- hive查询写文件报错Failed with exception Unable to move source hdfs:xx to destination xxx
- Message msg =new Message 与 obtainMessage区别
- 粒子群算法(三)局部版本
- nyu 的AI课的调度问题
- LightOJ 1028 Trailing Zeroes (I)
- SQL*Loader-522: lfiopn failed for file (xxx.log)
- Dual horsetail
- 粒子群算法(二)全局版本
- Table XXX is marked as crashed and should be repaired问题
- AirPlay无线技术研究
- raid5+lvm实验
- 使用个推的时候出现Installation error: INSTALL_FAILED_DUPLICATE_PERMISSION
- coderforce 519C A and B and Team Training
- 粒子群算法(一)
- WM_PAINT介绍及OnPaint()函数的作用原理
- Linux 命令行发邮件sendmail,mailutils,mutt msmtp