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

总结:

  1. 和1079同一类型。代码格式DFS:设置边界——树的递归
  2. 链接:【2019暑假刷题笔记-树的遍历】1079 Total Sales of Supply Chain

代码:

#include <stdio.h>
#include <vector>
#include <math.h>
using namespace std;
const int maxn=100010;
int total,ans_depth=0;
double price,r;
int ans;
/*
9 1.80 1.00
1 5 4 4 -1 4 5 3 6
*/
struct Node{vector<int> child;
}node[maxn];
void DFS(int index,int depth){if(node[index].child.size()==0){if(depth>ans_depth){ans_depth=depth;ans=1;}else if(depth==ans_depth){  //出错点,直接ans++没有判断 ans++;}return;}for(int i=0;i<node[index].child.size();i++){int child=node[index].child[i];DFS(child,depth+1);}
}
int main(){int id,k;scanf("%d %lf %lf",&total,&price,&r);r /= 100;for(int i=0;i<total;i++){scanf("%d",&id);if(id==-1){k=i;continue;}node[id].child.push_back(i);}DFS(k,0);printf("%.2lf %d",price*pow(r+1,ans_depth),ans);return 0;
}

【PAT】A1090 Highest Price in Supply Chain相关推荐

  1. 【PAT】A1106 Lowest Price in Supply Chain

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

  2. PAT (Advanced Level) Practice A1090 Highest Price in Supply Chain (25 分)(C++)(甲级)(树,深度)

    原题链接:A1090 Highest Price in Supply Chain #include<algorithm> #include<iostream> #include ...

  3. PAT甲级1090 Highest Price in Supply Chain:[C++题解]树、结点到根结点的距离、记忆化搜索、树形dp

    文章目录 题目分析 题目链接 题目分析 来源:acwing 和PAT甲级1079 Total Sales of Supply Chain:[C++题解] 树.结点到根结点的距离.树形dp.记忆化搜索是 ...

  4. 【PAT】A1079 Total Sales of Supply Chain

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

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

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

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

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

  7. PAT甲级1106 Lowest Price in Supply Chain:[C++题解]树、结点到根结点的距离、树形dp、记忆化搜索

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析:这道题是第三次做了. 和PAT甲级1079 Total Sales of Supply Chain:[C++题解] 树.结点到根结点的 ...

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

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

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

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

最新文章

  1. ubuntu16.04安装新版本golang
  2. 腾讯Android自动化测试实战3.1.4 Robotium的控件获取、操作及断言
  3. 网络基础(二)及HTTP协议
  4. 创建路径_PS钢笔工具是建立路径的基本工具
  5. hibernate reverse engineering 中没有java src folder
  6. java ext pagesize_更改透明图像的不透明度/更改extgstate字典的值
  7. python输出语句print i、j、k,python:在exec语句中获取打印输出
  8. pytorch初入门学习记录
  9. 【剑指 offer】(48)—— 不能被继承的类
  10. 光伏机器人最前线_高工机器人走进光伏:数字化车间未来可期
  11. html不用ajax怎么提交,停止HTML中JS AJAX功能提交按钮
  12. 卷积神经网络之“浅层特征”与“深层特征”
  13. win10计算机用户删除,Win10删除用户帐户的方法?如何在Win10中删除用户帐户
  14. 得物(毒)加密算法解析 得物逆向
  15. 简单版数独计算器-升级版
  16. iPhones刷机怎么备份微信记录 iPhone手机微信记录怎么备份
  17. 2021年危险化学品经营单位主要负责人考试及危险化学品经营单位主要负责人找解析
  18. 华为FreeBuds 5耳机声音变小怎么办?
  19. 优化代码中的“坏味道”
  20. matlab simulink 单相可调交流电源设计

热门文章

  1. c/c++头文件函数一览表
  2. STM32 SPI难点浅析
  3. AB1601开机运行后死机
  4. UNICODE与UTF-8的转换
  5. C++ Primer 5th笔记(9)chapter9 顺序容器 vector 容器的自增长 容器适配器
  6. 区块链BaaS云服务(11)招商银行ABS区块链平台
  7. 攻防世界Reverse第三题python-trade
  8. [密码学] 离散对数比特安全性
  9. 以管理员权限来进行解压操作
  10. 2020-10-25(极客pyc题目)