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. 与和1106题是一样的,不过这个题求最高价格。https://blog.youkuaiyun.com/hhuzxx/article/details/90775591
2. 输入也有点不一样,直接拿原来的代码改动一下就可以啦~
#include <iostream>
#include <vector>
using namespace std;
struct node{
double price;
vector<int> child;
};
vector<node> supply;
int N;
double r; //N个chain上的人,r%的比率
double P; //P为最初的价格
double maxPrice = -1;
int cnt = 0;
void dfs(int root, double p){
supply[root].price = p;
if(supply[root].child.size()== 0){ //到达叶子结点
if(maxPrice < p){
cnt = 1;
maxPrice = p;
}else if(maxPrice == p){
cnt++;
}
}
for (int i = 0; i < supply[root].child.size(); i++){
dfs(supply[root].child[i], p * (100+r)/100.0);
}
}
int main(){
scanf("%d %lf %lf", &N, &P, &r);
supply.resize(N);
int root = 0;
for (int i = 0; i < N; i++){
int k;
scanf("%d", &k);
if(k == -1)root = i;
else supply[k].child.push_back(i);
}
dfs(root,P);
printf("%.2f %d", maxPrice, cnt);
return 0;
}
本文介绍了一种计算供应链中从供应商到零售商的产品最高预期价格的方法。通过构建一个包含零售商、分销商和供应商的网络,每个成员根据一定的百分比加价率从其供应商购买产品,最终确定最高零售价格及达到此价格的零售商数量。
822

被折叠的 条评论
为什么被折叠?



