当前位置:网站首页>Pat grade a a1079 total sales of supply chain
Pat grade a a1079 total sales of supply chain
2022-07-18 04:32:00 【Zhemu】
A supply chain is a network of retailers( Retailer ), distributors( Distributor ), and suppliers( supplier )-- 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.00
3 2 3 5
1 9
1 4
1 7
0 7
2 6 1
1 8
0 9
0 4
0 3
Sample Output:
42.4The question :
There are suppliers ( The root node ), Distributor ( Child nodes of non leaf leaves ) And retailers ( leaf node ), A tree , Only retailers have the quantity of goods ( The weight ), Give the number of nodes, the price of goods and the percentage that will rise every time you pass through a store , Find the total price of all goods of all retailers of this tree ( The layers of retailers may be different ).
Ideas :
and 1090 I think about it , The leaf node has more weights , Build first , Then traverse the tree , Just calculate the maximum value .
Code :
// The tree of the relationship between number and node , Use the static method of tree ;
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
const int maxn=100010;
int child,n,k;
double p,r,ans=0; //ans Should be double type ;
struct node{
double data;// Cargo volume ( The weight ), Only leaf nodes have ;
vector<int > child;
}Node[maxn];
void DFS(int index,int depth){
if(Node[index].child.size()==0){
ans+=Node[index].data*pow(1+r,depth);
return ;// Recursive boundary ;;
}
for(int i=0;i<Node[index].child.size();i++)
DFS(Node[index].child[i],depth+1);
}
int main( ){
scanf("%d %lf %lf",&n,&p,&r);
r/=100;
// Build up trees , assignment :
for(int i=0;i<n;i++){
scanf("%d",&k);// Input i Number of sub nodes of node ;
if(k==0){// No child node is a leaf node , Only leaf nodes have cargo volume ( With power );
scanf("%lf",&Node[i].data);
}else{
for(int j=0;j<k;j++){// Child node number ;
scanf("%d",&child);
Node[i].child.push_back(child);
}
}
}
// Traversing the tree ;
DFS(0,0);
printf("%.1f",p*ans);// Price * Floating range = Rising prices , Price * Floating range * Cargo volume = The total value after the increase of total cargo volume , So you can first p Bring up , Calculate the floating amplitude of each node * Cargo volume , Finally, multiply by the original price to get the total value .
return 0;
}边栏推荐
- Why are the prices of industrial switches high and low?
- Is it safe for qiniu business school to open an account? Is it reliable? How can qiniu open an account
- 中金财富开户安全吗 开户有什么用
- 要连接 polardb 和 redis 需要进行哪些配置?
- 笔记本电脑能连接WiFi但浏览器无法打开网页的解决办法
- JVM内存模型——运行时数据区的特点和作用
- 钉钉开发文档
- XDC 2022 Intel技术专场:英特尔软硬件技术构筑云计算架构基石
- Intel IPU
- 现在网上开户安全么?想知道股票开账户如何优惠开户?
猜你喜欢

CMSIS-RTOS相关的一些内容
The practice of opengauss database on CentOS, configuration

Quickly deploy mqtt clusters on Alibaba cloud using terraform

Fungible DPU

动圈式扬声器过载过程

LM-Nav:基于语言、视觉和行为大模型的机器人导航方法

JVM garbage collection -- how to determine whether an object is garbage

Dynamic loudspeaker overload process

Pytorch分布式训练

Tinymce5.0.8 editor latest version Chinese version
随机推荐
荷兰蒂尔堡大学、联邦大学 | Neural Data-to-Text Generation Based on Small Datasets: Comparing the Added Value of Two Semi-Supervised Learning Approaches on Top of a Large Language Model(基于小数据集的神经数据到文本生成)
OKX 金融市场总监 Lennix Lai:Web3 是一场革命
开源数据质量解决方案——Apache Griffin入门宝典
PAT 甲级 A1094 The Largest Generation
同花顺周末能开户吗 开户安全吗
Gaussdb (DWS), the first benchmarking MySQL command collection article in the whole network
PAT 甲级 A1064 Complete Binary Search Tree
把一个数组封装成类
Daily question brushing record (24)
面试题:谈谈你对AQS 的理解
创意丝带样式登录页面
PAT 甲级 A1043 Is It a Binary Search Tree
P4 programmable network card in network computing
语句和表达式有什么不同
程序运行问题排查和解决:an instance of ‘std::logic_error‘what(): basic_string::_M_construct null not valid
Flat rider registration form
在 Polkadot 中进行创建的三种方式 —— 平行链、平行线程、智能合约
Why are the prices of industrial switches high and low?
Pythia:Facebook最新开源的视觉、语言多任务学习框架
[go to the heart of go]