PAT 1079. Total Sales of supply Chain (25)

Source: Internet
Author: User

1079. Total Sales of supply Chain (25)

A supply chain is a network of retailers (retailer), distributors (dealer), and suppliers (supplier)--everyone involved in moving a produ CT 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 Distribu Te them in a price, is r% higher than P. Only the retailers would face the customers. It is assumed this member in the supply chain have exactly one supplier except the root supplier, and there is no supp Ly cycle.

Now given a supply chain and you is supposed to tell the total sales from all the retailers.

Input Specification:

Each input file contains the 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 is 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 was the total number of distributors or retailers who receive products from supplier I, and are T Hen followed by the ID ' s of these distributors or retailers. Kj being 0 means that the j-th member was a retailer, then instead the total amount of the product would be given after Kj. All the numbers in a line is 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 the number would not be exceed 1010.

Sample Input:
10 1.80 1.003 2 3 51 91 41 70 72 6 11 80 90 40 3
1#include <iostream>2#include <vector>3#include <bitset>4#include <cmath>5#include <iomanip>6 7 using namespacestd;8 9 structNodeTen { Onevector<int>Vec; A     intLevel ; -     intcount; - }; the  -Node distributor[100000]; - DoubleTotal =0; - Doublep, R; +  - voidSetLevel (introot) + { A     if(Distributor[root].vec.empty ()) at     { -Total + = P*pow (1+r*1.0/ -, Distributor[root].level) *Distributor[root].count; -         return; -     }     -      for(inti =0; I < distributor[root].vec.size (); i++) -     { in         intChild =Distributor[root].vec[i]; -Distributor[child].level = Distributor[root].level +1; to SetLevel (child); +     } - } the  * intMain () $ {Panax Notoginseng     intN; -CIN >> n >> P >>R; the      for(inti =0; I < n; i++) +     { A         intnum, id; theCIN >>num; +         if(num = =0) -CIN >>Distributor[i].count; $          for(intj =0; J < num; J + +) $         { -CIN >>ID; - distributor[i].vec.push_back (ID); the         } -     }    Wuyidistributor[0].level =0; theSetLevel (0); -  Wucout <<fixed<< Setprecision (1) <<Total ; -}

PAT 1079. Total Sales of supply Chain (25)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.