1079. Total Sales of Supply Chain (25)

原创 2016年05月31日 19:53:12
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)【树+搜索】——PAT (Advanced Level) Practise

题目信息1079. Total Sales of Supply Chain (25)时间限制250 ms 内存限制65536 kB 代码长度限制16000 B A supply chain is...

1079. Total Sales of Supply Chain (25)

工厂只有一家,默认编号root=0; 工厂供货商+经销商+零售商=N(PS:编号0~N-1) 工厂直销价钱p 每经过一次转手增加的百分之r(比如买的时候p,转手卖给下一家为p=p*(100+1...

PAT 1079-Total Sales of Supply Chain (25)

时间限制 1000 ms 内存限制 65536 KB 代码长度限制 100 KB 判断程序 Standard 题目描述 A supply chain is a network of retaile...

PAT甲级真题及训练集(23)--1079. Total Sales of Supply Chain (25)(未全部测试通过,pat24分)

1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题...

1079. Total Sales of Supply Chain (25) -记录层的BFS改进

题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- ...

ZJU-PAT 1079. Total Sales of Supply Chain (25) 浙大2014年上机复试第三题

#include #include using namespace std; struct Node { int parent; //父节点 bool flag; //是否是re...

1079. Total Sales of Supply Chain

1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度...

Pat(Advanced Level)Practice--1079(Total Sales of Supply Chain)

Pat1079代码 题目描述: A supply chain is a network of retailers(零售商), distributors(经销商), and suppli...

1079. Total Sales of Supply Chain 解析

还是老样子的供应商问题,这次是给出了零售商手里有多少手机,全部卖出能卖多少钱。 提前把转手n次后的价格算出来,不然容易超时。 开始以为层数不会太大。。结果还是接近10^5的.... #include ...

PAT (Advanced Level) Practise 1079 Total Sales of Supply Chain (25)

1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:1079. Total Sales of Supply Chain (25)
举报原因:
原因补充:

(最多只允许输入30个字)