1090. Highest Price in Supply Chain (25)

102 篇文章 0 订阅
11 篇文章 0 订阅

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.00
1 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/12
1答案正确3957603/3
2答案正确3958123/3
3答案正确13081/1
4答案正确3232481/1
5答案正确13082/2
6答案正确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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值