# PAT甲级1090 Highest Price in Supply Chain (25分) 双vector来记录图 队列实现广搜

1090 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 (≤10​5​​), 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 S​i​​ is the index of the supplier for the i-th member. S​root​​ 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 10​10​​.
Sample Input:

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

Sample Output:

1.85 2

#include <iostream>
#include <string>
using namespace std;
#include<vector>
#include<algorithm>
#include<queue>
int sum(int n)//中序遍历
{
int out=0;
while(n!=0)
{
out+=n%10;
n=n/10;
}
return out;
}

int main()
{
int N;
double P;
double r;
cin>>N>>P>>r;
vector<vector<int>> vec(N);
int root;
for(int i=0; i<N; i++)
{
int num=i;//结点编号
int sup;
cin>>sup;//供应商
if(sup!=-1)
{
vec[sup].push_back(num);
}
else
root=num;
}
int level_num;

queue<int> que;
que.push(root);
int number=1;//有个测试点考察的就是最高价格就是根节点的价格，输出就是1
while(!que.empty())
{
queue<int> get;
while(!que.empty())
{
vector<int> number=vec[que.front()];
int start=que.front();
for(int i=0; i<number.size(); i++)
{

int endd=number[i];
get.push(number[i]);
}
que.pop();

}
if(get.size()!=0){ //这里是因为当进行到最后一个层次的时候，que的队列全部出栈，get为空
que=get;
number=get.size();
P=P*r*0.01+P;
}
}
printf("%.2f %d",P,number);
return 0;
}



09-04 62

08-12 30

12-01 504

08-14 319

08-25 88

08-16 288

04-29 119

02-25 21

02-07 57

02-13 85

05-03 312

12-31 126

05-02 20

04-14 59万+

03-13 15万+

03-01 13万+

03-04 14万+

03-08 5万+

03-08 7万+

04-25 6万+

03-10 13万+

03-12 11万+

03-13 11万+

03-14 1万+

03-18 9896

03-19 3万+

03-19 8万+

03-19 3万+

03-22 4万+

03-24 3万+

03-25 3万+

05-08 5万+

03-25 9万+

03-27 1万+

03-29 21万+

03-29 10万+

03-30 16万+

05-31 6264

05-31 1万+

04-02 5552

04-02 4万+

04-06 7万+

04-09 8万+

04-09 2万+

05-17 8544

04-11 3万+

04-15 6万+

04-18 4万+

04-20 4万+

04-24 3万+

04-29 7065

04-30 1万+

04-30 9567

05-01 6423

05-03 1万+

05-16 5万+

05-06 1万+

05-08 4万+

05-10 3303

05-14 6516

05-14 1986

05-16 3595

05-16 1万+

05-20 998

05-18 8418

05-27 1442

05-18 3612

05-19 1万+

05-21 7558

05-21 7582

05-27 5196

05-25 5391

05-23 6545

05-28 1671

05-23 3063

05-24 8472

#### java代码30行实现用我爱你重绘女朋友美照（我对你的爱，在每一个字里行间）

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客