PAT(甲级)1079
来源:互联网 发布:手机上编程软件 编辑:程序博客网 时间:2024/05/22 18:55
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.
Sample Input:10 1.80 1.003 2 3 51 91 41 70 72 6 11 80 90 40 3Sample Output:
42.4
#include <iostream>#include <deque>#include <vector>#include <cstring>#define SIZE 100005using namespace std;/////////////////////////////////////////////////////////////the key to success is to use//1.vector<vector<int> > v(SIZE);//2.simplify the representation of tree,eg, just use an array to represent//the node and storethe amounts of products, to those distributors or suppliers//which have its own distributors or retailors,use v[i] to//store them///////////////////////////////////////////////////////////////////deque<int> q;vector<vector<int> > v(SIZE);/*struct Node{Node(int n){number = n;value = 0;Next = NULL;}Node(){number = index++;value = 0;Next = NULL;}int number;int value;static int index;Node *Next;};int Node::index = 0;Node list1[SIZE];double pow(double r,int n){double res =1.0;while(n--){res *=r;}return res;}void display(Node list2[],int n){for(int i=0;i<n;i++){Node *p = &list2[i];while(p != NULL){cout <<p->number <<' ';p = p->Next;}cout <<endl;}}*/int list1[SIZE];int main(){//cout <<sizeof(v) << '\n';int count1,num,N;double p,r;//freopen("test.txt","r",stdin);memset(list1,0,sizeof(list1));scanf("%d%lf%lf",&N,&p,&r);r =r/100+1;double res=0.0;for(int i = 0;i<N;i++){ //creating chain listscanf("%d",&count1);//Node *p=&list1[i];if(count1){for(int j=0;j<count1;j++){scanf("%d",&num);/*Node *pnew = new Node(num);p->Next = pnew;p = p->Next;*/v[i].push_back(num);}}else scanf("%d",&list1[i]);}//display(list1,N);int level=0;count1 = 0; q.push_back(0); q.push_back(-1); double factor= p; while(count1 !=N){ int curr = q.front(); if(curr == -1){ level++; factor *=r; q.push_back(-1);}else{//Node *p = &list1[curr];//cout <<p->number <<' ';if(list1[curr]) res += list1[curr]*factor;else{/*p =p->Next; while(p != NULL){ q.push_back(p->number); p = p->Next; */q.insert(q.end(),v[curr].begin(),v[curr].end());}count1++;}q.pop_front();}printf("%.1lf\n",res);//fclose(stdin);return 0;}
- PAT(甲级)1079
- *浙大PAT甲级 1079
- PAT甲级1079
- PAT 甲级
- PAT甲级 A1025.PAT RANKING
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1003
- PAT(甲级)1004
- PAT(甲级)1005
- PAT(甲级)1006
- PAT(甲级)1007
- PAT(甲级)1008
- PAT(甲级)1009
- PAT(甲级)1010
- PAT(甲级)1011
- PAT(甲级)1012
- PAT(甲级)1013
- PAT(甲级)1014
- JAVA代理模式Proxy Pattern
- Eclipse安装swt插件
- Stm32-窗口看门狗实验
- 我的进阶曲线之五
- mysql 海量数据的存储和访问解决方案
- PAT(甲级)1079
- eclipse scala工程
- jquery中eq()与get()的区别
- (负载均衡)nginx+keepalive
- 工具类JdbcUtils
- Leetcode84: Integer to Roman
- jquery中prop()方法和attr()方法的区别浅析
- PAT(甲级)1080
- Java中的StringTokenizer类的使用方法