返回

1090 Highest 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 buys products from one's supplier in a price P and sell or distribute them in a price that is r% higher than P. 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 highest price we can expect from some retailers.

Input Specification:

Each input file contains one test case. For each case, The first line contains three positive numbers: N (≤10​5​​), the total number of the members in the supply chain (and hence they are numbered from 0 to N−1); P, the price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then the next line contains N numbers, each number S​i​​ is the index of the supplier for the i-th member. S​root​​ for the root supplier is defined to be −1. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print in one line the highest price we can expect from some retailers, accurate up to 2 decimal places, and the number of retailers that sell at the highest price. There must be one space between the two numbers. It is guaranteed that the price will not exceed 10​10​​.

Sample Input:

9 1.80 1.00
1 5 4 4 -1 4 5 3 6

Sample Output:

1.85 2
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn = 100010;
vector<int> child[maxn];double p, r;int n, maxdepth = 0, num = 0;void DFS(int index, int depth) {//depth类似于temp,用于比较得出最大深度if(child[index].size() == 0) {//到达子节点if (depth > maxdepth) {maxdepth = depth;num = 1;}else if (depth == maxdepth)num++;return;//注意return在第一层if里面}for (int i = 0; i < child[index].size(); i++) {DFS(child[index][i], depth + 1);}}int main() {int father, root;scanf("%d%lf%lf", &n, &p, &r);r /= 100;for (int i = 0; i < n; i++) {scanf("%d", &father);if (father != -1)child[father].push_back(i);else root = i;//根节点编号}DFS(root, 0);printf("%.2f %d\n", p*pow(1 + r, maxdepth), num);return 0;
}

1090 Highest Price in Supply Chain (25 分) 树的遍历:深度搜索+vector相关推荐

  1. PAT甲级 -- 1090 Highest Price in Supply Chain (25 分)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  2. 1090 Highest Price in Supply Chain (25 分)【难度: 一般 / 知识点: 树的遍历】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805376476626944 就是找深度最深的叶节点的深度,和最深的结点个 ...

  3. 1090 Highest Price in Supply Chain (25)(25 分)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  4. 1090. Highest Price in Supply Chain (25)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  5. 1090 Highest Price in Supply Chain (25)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  6. 1090. Highest Price in Supply Chain (25)-PAT甲级真题

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  7. PAT:1090. Highest Price in Supply Chain (25) AC

    #include<stdio.h> #include<vector> using namespace std; const int MAX=100010; int DEPest ...

  8. 1090. Highest Price in Supply Chain (25) dfs

    #include <iostream> #include <vector> #include <cmath> using namespace std;int n, ...

  9. 1090 Highest Price in Supply Chain(甲级)

    1090 Highest Price in Supply Chain (25分) A supply chain is a network of retailers(零售商), distributors ...

  10. 1090 Highest Price in Supply Chain (25 分)

    1090 Highest Price in Supply Chain (25 分) A supply chain is a network of retailers(零售商), distributor ...

最新文章

  1. python调用接口时传多个参数_python接口自动化11-post传data参数案例
  2. Ubuntu用apt-get安装报错:E: Could not get lock /var/lib/dpkg/lock-frontend - open (11:资源暂时不可用)
  3. 武汉轻工大学计算机学院操作系统复试题目,2016年武汉轻工大学数学与计算机学院计算机组成原理复试考研复试题库...
  4. vue实现侧边折叠菜单栏手风琴效果
  5. 信息学奥赛C++语言:最小数输出
  6. 为什么天朝互联网的三巨头是BAT
  7. 期许伟大-基于CMMI的过程改进之道探索
  8. Clark变换与Park(派克)变换
  9. Ubuntu 20.4 安装 Notepad++
  10. dedecms织梦 list列表页pagesize数量不对
  11. matlab向量乘法要加.,matlab中的矩阵与向量运算
  12. Graph_Master(连通分量_C_Trajan缩点+最小路径覆盖)
  13. 电脑桌面打开计算机打开多个,如何在电脑桌面并排显示多个Excel工作表
  14. 嵌入式作业STM32F103C8T6和stm32CubeMX实现LED灯
  15. (zzulioj1005)输入3个整数,输出它们的1次幂、2次幂和3次幂。
  16. IllegalArgumentException :argument type mismatch
  17. 【小程序】组件形式 引入第三方图标iconfont
  18. iOS内存分配与五大区域
  19. pyqt5中利用搜索框和按钮,搜索表中内容
  20. linux arm fpu初始化,如何确定Linux主板是否使用硬件FPU?

热门文章

  1. MLPlatform project的统一结构-----------Model层代码编写--------业务逻辑子层:编程思路...
  2. 【PHP设计模式 02_JieKou.php】面向接口开发
  3. CDHtmlDialog探索----WebBrowser扩展和网页Javascript错误处理
  4. java设计模式--创建模式--单例模式
  5. 剑指_3.2不修改数组找出重复的数字(Python)
  6. 上下相机贴合对位计算公式_ccd视觉自动对位贴合机主要应用在哪里?
  7. c#数据库连接总结2上篇(通过数据库进行登入和注册)
  8. 接口与抽象类的相同点和不同点
  9. python用模块读取xml文件_Python之xml文档及配置文件处理(ElementTree模块、ConfigParser模块)...
  10. win10默认安装路径修改_问题解答|Win10电脑重启桌面图标就变乱的解决方法!