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.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.4
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int maxn = 100010;struct node{double data;vector<int> child;
}Node[maxn];
int n;
double p,r,ans = 0;void DFS(int index,int depth){if(Node[index].child.size() == 0){//    printf("yezi %.lf\n",Node[index].data);// 验证 ans += Node[index].data * pow(1 + r, depth);return;}for(int i = 0; i < Node[index].child.size(); i++){//    printf("jiedian %d\n",Node[index].child[i]); //验证 aDFS(Node[index].child[i],depth+1);}
}
int main(){scanf("%d%lf%lf",&n,&p,&r);r /= 100;int k,child;for(int i = 0; i < n; i++){scanf("%d",&k);if(k == 0) scanf("%lf",&Node[i].data); //零售商的货物else{for(int j = 0; j < k; j++){scanf("%d",&child);Node[i].child.push_back(child);}}     }DFS(0,0); printf("%.1f",p * ans);
} 

 

转载于:https://www.cnblogs.com/wanghao-boke/p/8572097.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/385389.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

chdir、getcwd、mkdir、rmdir函数

#include <unistd.h> int chdir(const char *path); int fchdir(int fd); 作用&#xff1a;改变调用这一函数的进程&#xff08;即程序执行&#xff09;的当前工作目录&#xff0c;注意不是shell的当前工作目录。 返回值&#xff1a;0成功 -1失败 #include <unis…

【Leetcode | 235】 235. 二叉搜索树的最近公共祖先

给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先。 百度百科中最近公共祖先的定义为&#xff1a;“对于有根树 T 的两个结点 p、q&#xff0c;最近公共祖先表示为一个结点 x&#xff0c;满足 x 是 p、q 的祖先且 x 的深度尽可能大&#xff08;一个节点也可以是它自己…

1090. Highest Price in Supply Chain (25)

A supply chain is a network of retailers&#xff08;零售商&#xff09;, distributors&#xff08;经销商&#xff09;, and suppliers&#xff08;供应商&#xff09;-- everyone involved in moving a product from supplier to customer. Starting from one root suppli…

opendir、readdir和closedir函数

注意&#xff1a;在Linux中&#xff0c;目录的输入格式&#xff1a;/mnt//fghs、/mnt/fghs、/mnt/fghs和/mnt/fghs//是等效的&#xff0c;都一样。 #include <sys/types.h> #include <dirent.h> DIR *opendir(const char *name); DIR *fdopendir(int fd); 返回…

146. LRU缓存机制

运用你所掌握的数据结构&#xff0c;设计和实现一个 LRU (最近最少使用) 缓存机制。它应该支持以下操作&#xff1a; 获取数据 get 和 写入数据 put 。 获取数据 get(key) - 如果密钥 (key) 存在于缓存中&#xff0c;则获取密钥的值&#xff08;总是正数&#xff09;&#xff…

dup和dup2函数

#include <unistd.h> int dup(int oldfd); int dup2(int oldfd, int newfd); 作用&#xff1a;dup函数实现对一个文件的文件描述符进行复制&#xff0c;复制之后该进程就会新增加一一个文件描述符指向该文件&#xff08;即实现同一个文件对应多个文件描述符&#xff0…

fcntl函数(网络编程会用)

#include <unistd.h> #include <fcntl.h> int fcntl&#xff08;int fd, int cmd&#xff09;&#xff1b; int fcntl&#xff08;int fd, int cmd, long arg&#xff09;&#xff1b;//long 长整型 int fcntl&#xff08;int fd, int cmd, struct flock *lock…

189. 旋转数组

给定一个数组&#xff0c;将数组中的元素向右移动 k 个位置&#xff0c;其中 k 是非负数。 示例 1: 输入: [1,2,3,4,5,6,7] 和 k 3 输出: [5,6,7,1,2,3,4] 解释: 向右旋转 1 步: [7,1,2,3,4,5,6] 向右旋转 2 步: [6,7,1,2,3,4,5] 向右旋转 3 步: [5,6,7,1,2,3,4]示例 2: 输…

58. 最后一个单词的长度

给定一个仅包含大小写字母和空格 的字符串&#xff0c;返回其最后一个单词的长度。 如果不存在最后一个单词&#xff0c;请返回 0 。 说明&#xff1a;一个单词是指由字母组成&#xff0c;但不包含任何空格的字符串。 示例: 输入: "Hello World" 输出: 5 clas…

CPU和MMU(内存管理单元)

CPU的架构&#xff1a;要求能够理解从源程序到微指令的整个经历过程&#xff1a;存储器的层次结构&#xff08;网络资源下载到硬盘、磁盘缓存、内存、Cache、寄存器&#xff09;&#xff1b;CPU的四大部分&#xff1a;ALU、CU、中断系统和寄存器&#xff1b;程序执行的整个过程…

【C++ Primer | 09】容器适配器

一、stack s.push(): 向栈内压入一个成员&#xff1b; s.pop(): 从栈顶弹出一个成员&#xff1b; s.empty(): 如果栈为空返回true&#xff0c;否则返回false&#xff1b; s.top(): 返回栈顶&#xff0c;但不删除成员&#xff1b; s.size(): 返回栈内元素…

进程控制块PCB(进程描述符)

&#xff08;1&#xff09;PCB 每个进程在内核中都有一个进程控制块&#xff08;PCB&#xff09;来维护进程相关的信息&#xff0c;Linux内核的进程控制块是task_struct结构体。grep -r “task_struct” / 可以查找根目录下&#xff0c;包含task_struct的文件文件。或者 find…

103. 二叉树的锯齿形层次遍历

给定一个二叉树&#xff0c;返回其节点值的锯齿形层次遍历。&#xff08;即先从左往右&#xff0c;再从右往左进行下一层遍历&#xff0c;以此类推&#xff0c;层与层之间交替进行&#xff09;。 例如&#xff1a; 给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 /…

fork、getpid、getppid函数

#include <unistd.h> pid_t fork(void); 作用&#xff1a;创建一个子进程。 到目前为止&#xff0c;我们可以直到两种创建进程的方法&#xff1a;1. 通过执行二进制文件来创建一个进程&#xff0c;如&#xff1a;./a.out /bin/ls&#xff1b;2.通过fork函数来创建一个…

107. 二叉树的层次遍历 II

给定一个二叉树&#xff0c;返回其节点值自底向上的层次遍历。 &#xff08;即按从叶子节点所在层到根节点所在的层&#xff0c;逐层从左向右遍历&#xff09; 例如&#xff1a; 给定二叉树 [3,9,20,null,null,15,7], 3/ \9 20/ \15 7返回其自底向上的层次遍历为&#xff…

循环创建N个子进程

以循环创建5个进程为例&#xff0c;给出如下代码&#xff0c;分析其错误&#xff1a; #include <stdio.h> #include <stdlib.h> #include <unistd.h>int main(void) {int i;pid_t pid;printf("xxxxxxxxxxx\n");for (i 0; i < 5; i){pid fork…

【C++ Primer | 19】控制内存分配

1. 测试代码&#xff1a; #include <iostream> #include <new> #include <cstring> #include <cstdlib> using namespace std;void* operator new(size_t size) {cout << "global Override operator new" << endl;if (void* p…

getuid、geteuid、getgid和getegid函数

#include <unistd.h> #include <sys/types.h> uid_t getuid(void); uid_t geteuid(void); 作用&#xff1a;getuid返回当前进程的实际用户ID&#xff1b;geteuid返回当前用户的有效用户ID。这两个总是成功&#xff0c;不会失败。 #include <unistd.h> #…

【第15章】虚函数

一、为什么基类中的析构函数要声明为虚析构函数&#xff1f; 直接的讲&#xff0c;C中基类采用virtual虚析构函数是为了防止内存泄漏。具体地说&#xff0c;如果派生类中申请了内存空间&#xff0c;并在其析构函数中对这些内存空间进行释放。假设基类中采用的是非虚析构函数&am…

进程共享(读时共享写时复制)

父子进程之间在刚fork后。父子相同处: 全局变量、.data、.bbs、.text、栈、堆、环境变量、用户ID、宿主目录&#xff08;进程用户家目录&#xff09;、进程工作目录、信号处理方式等等&#xff0c;即0~3G的用户空间是完全一样的。父子不同处: 1.进程ID 2.fork返回值 3.父进…