1090. Highest Price in Supply Chain (25)

野性酷女 2022-05-30 03:53 216阅读 0赞

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:

  1. 9 1.80 1.00
  2. 1 5 4 4 -1 4 5 3 6

Sample Output:

  1. 1.85 2

题目大意:

代码:

  1. #include<stdio.h>
  2. #include<vector>
  3. #include<queue>
  4. using namespace std;
  5. struct node
  6. {
  7. int level;
  8. double price;
  9. vector<int> v;
  10. }person[100001];
  11. int levelnum[100001];
  12. int main()
  13. {
  14. int i,j,n,m,k,t;
  15. double price,rate;
  16. scanf("%d %lf %lf",&n,&price,&rate);
  17. for(i=0;i<n;i++)
  18. {
  19. scanf("%d",&m);
  20. if(m==-1)
  21. k=i;
  22. else
  23. person[m].v.push_back(i);
  24. }
  25. queue<int> q;
  26. q.push(k);
  27. person[k].level=1;
  28. person[k].price=price;
  29. int Max=0;
  30. double Maxprice=0;
  31. while(!q.empty())
  32. {
  33. int tmp=q.front();
  34. q.pop();
  35. levelnum[person[tmp].level]++;
  36. if(person[tmp].level>Max)
  37. {
  38. Max=person[tmp].level;
  39. Maxprice=person[tmp].price;
  40. }
  41. for(i=0;i<person[tmp].v.size();i++)
  42. {
  43. q.push(person[tmp].v[i]);
  44. person[person[tmp].v[i]].level=person[tmp].level+1;
  45. person[person[tmp].v[i]].price=person[tmp].price*(1+rate/100);
  46. }
  47. }
  48. printf("%.2lf %d\n",Maxprice,levelnum[Max]);
  49. return 0;
  50. }

发表评论

表情:
评论列表 (有 0 条评论,216人围观)

还没有评论,来说两句吧...

相关阅读

    相关 1090 危险品装箱 (25 分)

    集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里。比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸。 本题给定一张不相容物品的清单,需要你检查每一张集

    相关 1090 危险品装箱(25分)解析

    1090 危险品装箱 (25 分) 集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里。比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸。 本题给