1090. Highest Price in Supply Chain (25)

来源:互联网 发布:上海盘石软件电话 编辑:程序博客网 时间:2024/05/16 09:35

1090. Highest Price in Supply Chain (25)

时间限制
200 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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.001 5 4 4 -1 4 5 3 6
Sample Output:
1.85 2

零售商+经销商+厂商=N(代号0~N-1) 厂家直销价格p 每次转手价格增加百分之r
N个数(代表0~N-1从对应的代号买的,当数为-1,说明这家是厂家)
求消费者可以预期到最高价格是多少,并给出count家卖的价格是这个最高的

评测结果

时间结果得分题目语言用时(ms)内存(kB)用户8月18日 21:08答案正确251090C++ (g++ 4.7.2)395812datrilla

测试点

测试点结果用时(ms)内存(kB)得分/满分0答案正确130812/121答案正确3957603/32答案正确3958123/33答案正确13081/14答案正确3232481/15答案正确13082/26答案正确3543803/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;}
0 0
原创粉丝点击