zoukankan      html  css  js  c++  java
  • 1106 Lowest Price in Supply Chain (25)

    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 lowest price a customer can expect from some retailers.

    Input Specification:

    Each input file contains one test case. For each case, The first line contains three positive numbers: N (<=10^5^), 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 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:

    K~i~ ID[1] ID[2] ... ID[K~i~]

    where in the i-th line, K~i~ 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. K~j~ being 0 means that the j-th member is a retailer. All the numbers in a line are separated by a space.

    Output Specification:

    For each test case, print in one line the lowest price we can expect from some retailers, accurate up to 4 decimal places, and the number of retailers that sell at the lowest price. There must be one space between the two numbers. It is guaranteed that the all the prices will not exceed 10^10^.

    Sample Input:

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

    Sample Output:

    1.8362 2


     1 #include<iostream>
     2 #include<cmath>
     3 #include<vector>
     4 using namespace std;
     5 vector<int> num(100002, 0);
     6 vector<vector<int>> v;
     7 int minn=99999999;
     8 void dfs(int root, int depth){
     9   if(v[root].size()==0){
    10     num[depth]++;
    11     if(depth<minn) minn=depth;
    12   }
    13   for(int i=0; i<v[root].size(); i++) dfs(v[root][i], depth+1);
    14 }
    15 int main(){
    16   int n, i;
    17   double p, r;
    18   cin>>n>>p>>r;
    19   v.resize(n);
    20   for(i=0; i<n; i++){
    21     int j, k, leaf;
    22     cin>>k;
    23     for(j=0; j<k; j++){
    24       scanf("%d", &leaf);
    25       v[i].push_back(leaf);
    26     }
    27   }
    28   dfs(0, 0);
    29   printf("%.4f %d", p*pow(1.0+r/100.0, minn), num[minn]);
    30   return 0;
    31 }
    有疑惑或者更好的解决方法的朋友,可以联系我,大家一起探讨。qq:1546431565
  • 相关阅读:
    Linux系统调优方法
    递归(Recursion)算法
    数据结构之链表
    【日常摸鱼】牛客挑战赛2
    【日常摸鱼】牛客挑战赛1
    组合计数学习笔记1
    To-Do List 2
    20199112 2019-2020-2 《网络攻防实践》第 3 周作业
    Flutter上线项目实战——腾讯点播直播下载
    打开旧Flutter项目说:Your Flutter application is created using an older version of the Android embedding
  • 原文地址:https://www.cnblogs.com/mr-stn/p/9160742.html
Copyright © 2011-2022 走看看