• 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. }

     

  • 相关阅读:
    VBA解决Windows空当接龙的617局
    Ubuntu 优化 与 问题记录
    基于JavaWeb的居民户籍管理系统设计与实现
    香港服务器运行不正常原因简析
    C#语言实例源码系列-实现批量图片格式转换
    VTK编译解决CMake的“could not find any instance of Visual Studio”的问题
    模仿CSDN黑暗帝国动态背景的vue项目(附源码)
    技术贴 | Rocksdb 中 Memtable 源码解析
    MemGPT: Towards LLMs as Operating Systems
    学习在php中将特大数字转成带有千/万/亿为单位的字符串
  • 原文地址:https://blog.csdn.net/weixin_53199925/article/details/126581523