博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1079 Total Sales of Supply Chain
阅读量:6896 次
发布时间:2019-06-27

本文共 1147 字,大约阅读时间需要 3 分钟。

hot3.png

结构体+树的BFS就过了

#include 
#include 
#include 
using namespace std;int n;double p, r;double totalSale;typedef struct node{ int id; int cn;//child数量 vector
 child; int amount; double price;};node nodes[100000+5];queue
 q;void bfs(){ while(!q.empty()){ node cur = q.front(); q.pop(); if(cur.cn == 0){//叶子 totalSale += cur.amount * cur.price; continue; } double nextPrice = cur.price * (1 + r/100); for(int i = 0; i < cur.cn; i++){ int childId = cur.child[i]; nodes[childId].price = nextPrice; q.push(nodes[childId]);//入队 } } }int main(){ freopen("in.txt","r",stdin); scanf("%d %lf %lf",&n, &p, &r); for(int i = 0; i < n; i++){ node tmp; tmp.id = i; scanf("%d", &tmp.cn); if(tmp.cn > 0){ int child; for(int j = 0; j < tmp.cn; j++){ scanf("%d", &child); tmp.child.push_back(child); } tmp.amount = 0; }else{ scanf("%d", &tmp.amount); } tmp.price = 0.0; nodes[i] = tmp; } totalSale =  0.0; nodes[0].price = p; q.push(nodes[0]); bfs(); printf("%.1lf", totalSale); return 0;}

转载于:https://my.oschina.net/kaneiqi/blog/307470

你可能感兴趣的文章
如何用Python写一个贪吃蛇AI
查看>>
nginx全局变量
查看>>
今日一练习
查看>>
Kylin 在 58 集团的实践和应用
查看>>
javascript性能优化
查看>>
41. First Missing Positive
查看>>
sql的行转列(PIVOT)与列转行(UNPIVOT)
查看>>
sbt配置——数据源问题解决
查看>>
框架模式与设计模式之区别
查看>>
AngularJS+Satellizer+Node.js+MongoDB->Instagram-13
查看>>
CSS 实现打字效果
查看>>
jquery 根据已知值来修改单选框的被选中项
查看>>
html5 aside
查看>>
并发线程学习001(volatile 使用)
查看>>
JSONArray().fromObject(); 出现org.apache.catalina.core.StandardWrapperValve invoke错误的解决办法...
查看>>
取余和取模的小结
查看>>
JAVA应用CPU占用100%|内存泄漏分析总结
查看>>
SVN使用笔记-cleanup解决资源锁定(locked)
查看>>
又一个开始
查看>>
ecshop_邮件设置
查看>>