1079. Total Sales of Supply Chain (25)

来源:互联网 发布:网络歌手小右照片 编辑:程序博客网 时间:2024/06/10 12:38

1079. Total Sales of Supply Chain (25)

时间限制
250 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. Only the retailers will face the customers. 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 total sales from all the 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 their ID's are numbered from 0 to N-1, and the root supplier's ID is 0); P, the unit price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then N lines follow, each describes a distributor or retailer in the following format:

Ki ID[1] ID[2] ... ID[Ki]

where in the i-th line, Ki is the total number of distributors or retailers who receive products from supplier i, and is then followed by the ID's of these distributors or retailers. Kj being 0 means that the j-th member is a retailer, then instead the total amount of the product will be given after Kj. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print in one line the total sales we can expect from all the retailers, accurate up to 1 decimal place. It is guaranteed that the number will not exceed 1010.

Sample Input:
10 1.80 1.00 3 2 3 5 1 9 1 4 1 7 0 7 2 6 1 1 8 0 9 0 4 0 3
Sample Output:
42.4
工厂只有一家,默认编号root=0;
工厂供货商+经销商+零售商=N(PS:编号0~N-1)   工厂直销价钱p   每经过一次转手增加的百分之r(比如买的时候p,转手卖给下一家为p=p*(100+1)/100)
接着N行(代表编号0~N-1的买或卖),这N行形式有两种【一种:   0    买的个数count;
                                           【另一:  卖给num个  接着num个来买的人的编号id1 id2……idnum;
求出那些买的【入手价钱*他买的个数count】的总和;
我下面用的是从工厂root开始BFS广度搜索,找买的就加到sum里面;需要特别注意的是,如果这家工厂全部直销,那么结果就是工厂的直销价格p*这家工厂的count(当N行中的第一行是【  0 count  】这种形式,说明工厂全部直销)

评测结果

时间结果得分题目语言用时(ms)内存(kB)用户8月17日 10:46答案正确251079C++ (g++ 4.7.2)757012datrilla

测试点

测试点结果用时(ms)内存(kB)得分/满分0答案正确118012/121答案正确13001/12答案正确7568962/23答案正确5667082/24答案正确13083/35答案正确6870122/26答案正确6467043/3

#include<iostream>  #include<vector> #include<iomanip>#include<queue>using namespace std; struct Sales{  bool retailers;  vector<int> sup;  Sales(bool f) :retailers(f){}};struct Goods{  int supplier;  double price;  Goods(){}  Goods(int s,double p):supplier(s),price(p){}};void readln(vector<Sales>*soldpeople, int N){  int index, people,num;  for (index = 0; index < N;index++)  {    cin >> num;    if (num == 0)    {      cin >> people;      (*soldpeople)[index].retailers = true;      (*soldpeople)[index].sup.push_back(people);     }    else    {      while (num--)      {        cin >> people;        (*soldpeople)[index].sup.push_back(people);       }     }  }}double BFSsale(vector<Sales>*soldpeople, int root, double p, double r){  double sum = 0.0;  queue<Goods>Q;   if ((*soldpeople)[root].retailers)  {    return p*(*soldpeople)[root].sup[0];  }  Q.push(Goods(root, p));   while (!Q.empty())  {     root = Q.front().supplier;    p = Q.front().price*(100+r)/100;     Q.pop();     for (vector<int>::iterator iter =(*soldpeople)[root].sup.begin(); iter!= (*soldpeople)[root].sup.end(); iter++)    {       if ((*soldpeople)[*iter].retailers)      {        sum =sum +p*(*soldpeople)[(*iter)].sup[0];       }      else Q.push(Goods((*iter), p));    }    }   return sum;   }int main(){  int N;  double r,p;  cin >> N >> p >> r;  vector<Sales>soldpeople(N,Sales(false));  readln(&soldpeople, N);  cout << setiosflags(ios::fixed) << setprecision(1) << BFSsale(&soldpeople, 0, p, r) << endl;;    system("pause");  return 0;}
0 0