zoukankan      html  css  js  c++  java
  • 1090. Highest Price in Supply Chain (25)

     

    时间限制
    200 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    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. 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 highest price we 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 (<=105), the total number of the members in the supply chain (and hence they are numbered from 0 to N-1); P, the price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then the next line contains N numbers, each number Si is the index of the supplier for the i-th member. Sroot for the root supplier is defined to be -1. All the numbers in a line are separated by a space.

    Output Specification:

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

    Sample Input:
    9 1.80 1.00
    1 5 4 4 -1 4 5 3 6
    
    Sample Output:
    1.85 2
     1 #include<stdio.h>
     2 #include<vector>
     3 #include<math.h>
     4 using namespace std;
     5 
     6 struct Node
     7 {
     8     int level;
     9     vector<int> child;
    10 };
    11 
    12 Node Tree[100001];
    13 bool visit[100001];
    14 
    15 int MAX;
    16 
    17 vector<int> Maxque;
    18 
    19 void DFS(int root,int level,double price,double rate)
    20 {
    21     visit[root] = true;
    22     if(Tree[root].child.empty())
    23     {
    24         Maxque.push_back(level);
    25         if(level > MAX ) MAX = level;
    26     }
    27     else
    28     {
    29         for(int i = 0 ;i < Tree[root].child.size();i++)
    30         {
    31             if(visit[Tree[root].child[i]] == false)
    32                 DFS(Tree[root].child[i],level+1,price,rate);
    33         }
    34     }
    35 }
    36 
    37 int main()
    38 {
    39   int ID,num,i,root;
    40   double price,rate;
    41   scanf("%d%lf%lf",&num,&price,&rate);
    42   for( i = 0; i < num ;i++)
    43   {
    44       Tree[i].child.clear();
    45       visit[i]= false;
    46   }
    47   for(i = 0 ;i < num ;i ++)
    48   {
    49      scanf("%d",&ID);
    50      if(ID != -1)
    51      Tree[ID].child.push_back(i);
    52      else root = i;
    53   }
    54   
    55     int level = 0;
    56     MAX = -1;
    57     DFS(root,level,price,rate);
    58     
    59     int count = 0;
    60     for(i = 0;i< Maxque.size() ;i++)
    61         if( Maxque[i] == MAX ) ++count;
    62     printf("%0.2lf %d
    ",price*pow( (100+rate)/100,MAX),count);
    63 
    64   return 0;
    65 }


  • 相关阅读:
    8款超酷体验的jQuery/CSS3应用插件
    6款基于SVG的HTML5CSS3应用和动画
    精妙无比 8款HTML5动画实例及源码
    超赞值得一试的六款jQuery插件和CSS3应用
    不容错过的七个jQuery图片滑块插件
    7款值得你心动的HTML5动画和游戏
    8款HTML5动画特效推荐源码
    绝对震撼 7款HTML5动画应用及源码
    8款超酷而实用的CSS3按钮动画
    10款强大的jQuery/HTML5应用新鲜出炉
  • 原文地址:https://www.cnblogs.com/xiaoyesoso/p/4282957.html
Copyright © 2011-2022 走看看