# 1079. Total Sales of Supply Chain (25)

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.

IDEA

1.树的存储，vecttor<vector<int>> tree(n)，置空操作tree[i].clear();

2.用层序遍历实现，用到queue

CODE

#include<iostream>
#include<vector>
#include<queue>
#include<iomanip>
#include<fstream>
using namespace std;
int main(){
//	freopen("input.txt","r",stdin);
int n;
double price,r;
cin>>n>>price>>r;

vector< vector<int> > tree(n);
vector<int> retailer(n,0);

for(int i=0;i<n;i++){
int k;
cin>>k;
int num;
if(k==0){
cin>>num;
retailer[i]=num;
tree[i].clear();
}else{
for(int j=0;j<k;j++){
cin>>num;
tree[i].push_back(num);
}
}
}
//	vector<int>::iterator it;
//	for(it=retailer.begin();it!=retailer.end();it++){
//		cout<<*it<<" ";
//	}

queue<int> que;
int root=0;
que.push(root);

int last=root,tail=root;
double factor=price;
double sum=0;
while(!que.empty()){
int tmp=que.front();
que.pop();
sum+=retailer[tmp]*factor;
for(int i=0;i<tree[tmp].size();i++){
int num=tree[tmp][i];
que.push(num);
tail=num;
}
if(tmp==last){
factor*=(1+r/100);
last=tail;
}
}
cout<<fixed<<setprecision(1)<<sum;
//	fclose(stdin);
return 0;
}

• 本文已收录于以下专栏：

## 1079. Total Sales of Supply Chain (25)解题报告

#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include using namespace std...
• chr1991
• 2016年11月06日 10:33
• 94

## 1079 Total Sales of Supply Chain

A supply chain is a network of retailers（零售商）, distributors（经销商）, and suppliers（供应商）– everyone invol...
• Win_Man
• 2016年02月28日 18:29
• 183

## 1079. Total Sales of Supply Chain (25)

1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 ...
• artemisrj
• 2014年03月25日 21:24
• 739

## 1079. Total Sales of Supply Chain

Tips: 真是no zuo no die.说好的尽量用C来写,脑子一抽,又用Java来写了,最直接的方法,结果来了个超时.好吧,以为是算法问题,继续改,各种思路,仍得不到解决.换C++吧,还是各种思...
• Thare_Lam
• 2015年10月14日 19:39
• 459

## PAT (Advanced Level) 1079. Total Sales of Supply Chain (25) 总叠加售价 BFS

A supply chain is a network of retailers（零售商）, distributors（经销商）, and suppliers（供应商）-- everyone invo...
• tuzigg123
• 2015年07月29日 22:08
• 386

## 1079. Total Sales of Supply Chain (25) dfs

A supply chain is a network of retailers（零售商）, distributors（经销商）, and suppliers（供应商）-- everyone invo...
• qq_31474267
• 2018年02月11日 01:23
• 45

## 【PAT】1079. Total Sales of Supply Chain (25)

A supply chain is a network of retailers（零售商）, distributors（经销商）, and suppliers（供应商）-- everyone invo...
• realxuejin
• 2015年10月21日 20:47
• 282

## PAT 1079. Total Sales of Supply Chain (25)

1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 32000 kB 代码长度限制 160...
• solin205
• 2014年03月25日 14:59
• 549

## 1079. Total Sales of Supply Chain (25) - 1106. Lowest Price in Supply Chain (25) 类树操作

1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题...
• qq_26437925
• 2015年10月03日 09:06
• 338

## 1079. Total Sales of Supply

cout )
• u013827143
• 2014年07月03日 22:29
• 243

举报原因： 您举报文章：1079. Total Sales of Supply Chain (25) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)