码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 1079 Total Sales of Supply Chain


    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.

    Starting from one root supplier, everyone on the chain buys products from one's supplier in a price P and sell or distribute them in a price that is r% higher than P. Only the retailers will face the customers. It is assumed that each member in the supply chain has exactly one supplier except the root supplier, and there is no supply cycle.

    Now given a supply chain, you are supposed to tell the total sales from all the retailers.

    Input Specification:

    Each input file contains one test case. For each case, the first line contains three positive numbers: N (≤105), the total number of the members in the supply chain (and hence their ID's are numbered from 0 to N−1, and the root supplier's ID is 0); P, the unit price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then N lines follow, each describes a distributor or retailer in the following format:

    Ki​ ID[1] ID[2] ... ID[Ki​]

    where in the i-th line, Ki​ is the total number of distributors or retailers who receive products from supplier i, and is then followed by the ID's of these distributors or retailers. Kj​ being 0 means that the j-th member is a retailer, then instead the total amount of the product will be given after Kj​. All the numbers in a line are separated by a space.

    Output Specification:

    For each test case, print in one line the total sales we can expect from all the retailers, accurate up to 1 decimal place. It is guaranteed that the number will not exceed 1010.

    Sample Input:

    1. 10 1.80 1.00
    2. 3 2 3 5
    3. 1 9
    4. 1 4
    5. 1 7
    6. 0 7
    7. 2 6 1
    8. 1 8
    9. 0 9
    10. 0 4
    11. 0 3

    Sample Output:

    42.4

    dfs:

    1. #include
    2. #include
    3. #include
    4. using namespace std;
    5. vector<int>g[100010];
    6. int cnt[100010];
    7. int n, t, x, num;
    8. double p, r, ans;
    9. void dfs(int i, double pp) {
    10. if (cnt[i]) {
    11. ans += pp * cnt[i];
    12. return;
    13. }
    14. for (int j = 0; j < g[i].size(); j++) {
    15. dfs(g[i][j], pp * (1.0 + r * 0.01));
    16. }
    17. }
    18. int main() {
    19. cin >> n >> p >> r;
    20. for (int i = 0; i < n; i++) {
    21. cin >> t;
    22. for (int j = 0; j < t; j++) {
    23. cin >> x;
    24. g[i].push_back(x);
    25. }
    26. if (t == 0) {
    27. cin >> x;
    28. cnt[i] = x;
    29. }
    30. }
    31. dfs(0, p);
    32. cout << setprecision(1) << fixed << ans;
    33. return 0;
    34. }

     

  • 相关阅读:
    【服务器数据恢复】IBM某型号服务器RAID5磁盘阵列数据恢复案例
    面试:系统启动流程简介
    2023年中国精准PCI行业发展规模及发展趋势分析:精准PCI日益普及[图]
    GitHub基本概念
    汽车电子相关术语
    【python科学文献计量】关于中国知网检索策略的验证,以事故伤害严重程度检索为例
    多御安全浏览器宝藏功能全新升级,建议低调使用
    Android 交叉编译openssl 、libxml2静态库
    (五)编译中出现的向后兼容问题
    计算机毕业设计Java校园二手交易系统(源码+系统+mysql数据库+Lw文档)
  • 原文地址:https://blog.csdn.net/weixin_53199925/article/details/126581523
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号