零售商+经销商+厂商=N(代号0~N-1) 厂家直销价格p 每次转手价格增加百分之r1090. Highest Price in Supply Chain (25)
时间限制200 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueA 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 6Sample Output:1.85 2
N个数(代表0~N-1从对应的代号买的,当数为-1,说明这家是厂家)
求消费者可以预期到最高价格是多少,并给出count家卖的价格是这个最高的
评测结果
时间 | 结果 | 得分 | 题目 | 语言 | 用时(ms) | 内存(kB) | 用户 |
---|---|---|---|---|---|---|---|
8月18日 21:08 | 答案正确 | 25 | 1090 | C++ (g++ 4.7.2) | 39 | 5812 | datrilla |
测试点
测试点 | 结果 | 用时(ms) | 内存(kB) | 得分/满分 |
---|---|---|---|---|
0 | 答案正确 | 1 | 308 | 12/12 |
1 | 答案正确 | 39 | 5760 | 3/3 |
2 | 答案正确 | 39 | 5812 | 3/3 |
3 | 答案正确 | 1 | 308 | 1/1 |
4 | 答案正确 | 32 | 3248 | 1/1 |
5 | 答案正确 | 1 | 308 | 2/2 |
6 | 答案正确 | 35 | 4380 | 3/3 |
#include<iostream> #include<vector> #include<queue> #include<iomanip> using namespace std; void readln(vector<vector<int>>*solds, int N,int &root) { int temp; for (int index = 0; index<N; index++) { cin >>temp; if (temp== -1)root = index; else (*solds)[temp].push_back(index); } } void BFSmaxprice(vector<vector<int>>*solds, double p, double r, double&maxprice,int &count,int root) { if ((*solds)[root].size() == 0) { maxprice = p; count = 1; } else { queue<pair<int, double>>Q; Q.push(make_pair(root, p )); while (!Q.empty()) { root = Q.front().first; p = Q.front().second*(100 + r) / 100; Q.pop(); for (vector<int>::iterator iter = (*solds)[root].begin(); iter != (*solds)[root].end(); iter++) { if ((*solds)[(*iter)].size() > 0) { Q.push(make_pair((*iter), p)); } else { if (0 == count ||p > maxprice) { count = 1; maxprice = p; } else if (p == maxprice)count++; } } } } } int main() { int N,root; double p, r,maxprice; cin >> N >> p >> r; vector<vector<int>>solds(N); readln(&solds, N, root); N = 0; BFSmaxprice(&solds, p, r, maxprice, N, root); cout << setiosflags(ios::fixed) << setprecision(2) <<maxprice<< " " << N << endl; system("pause"); return 0; }