【PAT甲级】1079 Total Sales of Supply Chain (25 分)

题意:

输入一个正整数N(<=1e5),表示共有N个结点,接着输入两个浮点数分别表示商品的进货价和每经过一层会增加的价格百分比。接着输入N行每行包括一个非负整数X,如果X为0则表明该结点为叶子结点接着输入一个整数表示该零售商进货的数量,X不为零则接着输入X个正整数表示它的下级经销商是哪些结点。输出所有零售商进货的总价。(结点从0~N-1,0为根节点即供应商)

代码:

#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[100007],lv[100007],ans[100007];
vector<int>v[100007];
void dfs(int x){
for(int it=0;it<v[x].size();++it){
lv[v[x][it]]=lv[x]+1;
dfs(v[x][it]);
}
return ;
}
int main(){
//ios::sync_with_stdio(false);
//cin.tie(NULL);
//cout.tie(NULL);
int n;
cin>>n;
double p,r;
cin>>p>>r;
int cnt=0;
for(int i=0;i<n;++i){
int x,num;
cin>>x;
if(!x){
cin>>num;
a[i]=num;
ans[++cnt]=i;
}
for(int j=1;j<=x;++j){
cin>>num;
v[i].push_back(num);
}
}
dfs(0);
double sum=0;
for(int i=1;i<=cnt;++i){
double tamp=1.0*a[ans[i]]*p*pow(1.0+0.01*r,lv[ans[i]]);
sum+=tamp;
}
printf("%.1lf",sum);
return 0;
}

原文地址:https://www.cnblogs.com/ldudxy/p/11823045.html

时间: 2024-07-31 21:58:59

【PAT甲级】1079 Total Sales of Supply Chain (25 分)的相关文章

PAT Advanced 1079 Total Sales of Supply Chain (25) [DFS,BFS,树的遍历]

题目 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 pr

PAT:1079. Total Sales of Supply Chain (25) AC

#include<stdio.h> #include<math.h> #include<vector> using namespace std; const int MAX=100010; int DEPest=0; int root=-1,N; double P,r,sum=0; vector<int> child[MAX]; //child[父亲][孩子] 二维数组表示树形结构 double price[MAX]; //记录叶子节点的权值 void DF

PAT 1079. Total Sales of Supply Chain (25)

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

PAT 甲级 1106 Lowest Price in Supply Chain (25分) (bfs)

1106 Lowest Price in 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 b

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 supplie

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

树的遍历. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<iostream> #include<algorithm> using namespace std

A1079 Total Sales of Supply Chain (25分)

一.技术总结 开始拿到这一题,知道用DFS但是不知道怎么设置递归式和递归边界,一直在想,其实就是该节点的子结点为0时就是终止时,递归式就是每次递归后,对于深度depth加一. 还有一点就是怎么解决所有费用相加的问题,开始还在想,用一个数组存储所有路径然后再,在遍历,是在太笨了,可以直接定义一个全局变量sum,然后出现递归边界时,就加上这个路径下产生的总费用. 还有就是要注意题中给出的输出格式,还有就是英文中数字1和字母l过于相似,切记可能出现错误. 同时如果定义为double,用%d输入可能出现

pat1079. Total Sales of Supply Chain (25)

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 c

PAT 1079 Total Sales of Supply Chain[比较]

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