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 }


  • 相关阅读:
    servlet基础讲解
    tomcat web.xml配置
    JavaScript Cookies
    窗口的自适应处理
    让Eclipse和NetBeans共享同一个项目
    maven基础知识
    JS中令人发指的valueOf方法介绍
    在iOS开发中使用FMDB
    苹果开发者账号那些事儿(三)
    苹果开发者账号那些事儿(二)
  • 原文地址:https://www.cnblogs.com/xiaoyesoso/p/4282957.html
Copyright © 2011-2022 走看看