zoukankan      html  css  js  c++  java
  • A1090. Highest 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. 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 <stdlib.h>
     3 #include <iostream>
     4 #include <string.h>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <string>
     8 #include <stack> 
     9 #include <queue>
    10 using namespace std;
    11 const int maxn=100010; 
    12 int n;
    13 double r,p,ans=0;
    14 
    15 vector<int> child[maxn];
    16 
    17 //求最大深度
    18 int maxdep=0,anscount=0; 
    19 void DFS(int root,int depth)
    20 {
    21  if(child[root].size()==0)
    22  {
    23      if(depth>maxdep){
    24          maxdep=depth;
    25          anscount=1;
    26      }else if(depth==maxdep)
    27      {
    28          anscount++;
    29      }else{
    30      }
    31  }
    32  for(int i=0;i<child[root].size();i++)
    33  {
    34      DFS(child[root][i],depth+1);
    35  }
    36 }
    37 int main(){
    38     
    39     scanf("%d %lf %lf",&n,&p,&r);
    40     r=r/100;
    41     int root;
    42     for(int i=0;i<n;i++)
    43     {
    44         int tmp;
    45         scanf("%d",&tmp);
    46         if(tmp==-1)
    47         {
    48          root=i;
    49         }else
    50         {
    51         child[tmp].push_back(i);    
    52         }
    53         
    54     }
    55     DFS(root,0);
    56     printf("%.2f %d",p*pow(1+r,maxdep),anscount);
    57     return 0;
    58 }
  • 相关阅读:
    作为【开发人员】如何持续提升自己的开发技能
    永远不要放弃做梦的权利---与所有程序员们共勉
    十种更好的表达“你的代码写的很烂”的方法---总有些人的代码让人难以忍受
    程序员技术练级攻略--练成这样,成神仙了!
    创业其实是个逻辑问题![想不想创业都来看看]
    多图震撼!数字的未来,2013报告
    记最难忘的一件事 等笑话一箩筐
    HDU4666 Hyperspace(曼哈顿)
    POJ3436 ACM Computer Factory(最大流)
    再思考
  • 原文地址:https://www.cnblogs.com/ligen/p/4320895.html
Copyright © 2011-2022 走看看