1090 Highest Price in Supply Chain

news/2024/7/3 14:52:21

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 (<=105), 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 Si is the index of the supplier for the i-th member. Sroot 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 1010.

Sample Input:

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

Sample Output:

1.85 2

#include<iostream>
#include<vector>
#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){
    if(child[index].size()==0){
        if(depth>maxDepth){
            maxDepth=depth;
            num=1;
        }else if(depth==maxDepth){
            num++;
        }
        return ;
    }
    for(int i=0;i<child[index].size();i++){
        DFS(child[index][i],depth+1);
    }
}
int main(){
    int father,root;
    cin>>n>>p>>r;
    r/=100;
    for(int i=0;i<n;i++){
        cin>>father;
        if(father!=-1){
            child[father].push_back(i);
        }
        else{
            root=i;
        }
    }
    DFS(root,0);
    printf("%.2f %d",p*pow(1+r,maxDepth),num);
}

http://www.niftyadmin.cn/n/4636570.html

相关文章

linux 设备文件和设备之间联系的建立

<设备驱动模型> 注&#xff1a;几乎所有的设备结构体都包含"strcut kobject kobj"和"srtuct list_head list"该结构体。struct kobject kobj: 该结构体用于构建Linux设备驱动模型的模型建立 struct list_head { struct list_head *prev,*next; }; 该…

mysql-存储过程-触发器-事务---4

本节所讲内容&#xff1a; 存储过程 触发器事务一、存储过程 什么是存储过程 大多数SQL语句都是针对一个或多个表的单条语句。并非所有的操作都怎么简单。经常会有一个完整的操作需要多条才能完成。存储过程&#xff08;Stored Procedure&#xff09;是在大型数据库系统中&…

Linux系统安装与初用 实验报告

南京信息工程大学实验报告 一、实验目的 1.掌握 linux 系统的安装方法 2.理解 linux 系统安装过程中涉及的基础知识 3.熟悉 linux 系统的操作环境 4.尝试简单的 linux shell 命令 二、实验准备 1. 围绕下述问题结合教材、课件、互联网学习指定内容。 问题&#xff1a; &#xf…

Maven学习笔记三(Eclipse创建Maven项目)

配置 Eclipse Maven 环境1.配置 Manen 地址将下载的Maven导入进来&#xff0c;然后勾选使用2.设置 setting.xml 地址选中Maven下conf目录下的settings.xml&#xff0c;然后local Repository会自动识别出设置的local Repository创建 Maven 项目选中模板 &#xff08;如果是创建w…

1058 A+B in Hogwarts easy

If you are a fan of Harry Potter, you would know the world of magic has its own currency system — as Hagrid explained it to Harry, “Seventeen silver Sickles to a Galleon and twenty-nine Knuts to a Sickle, it’s easy enough.” Your job is to write a progr…

Java-API简析_java.io.InputStreamReader类(基于 Latest JDK)(浅析源码)

【版权声明】未经博主同意&#xff0c;谢绝转载&#xff01;&#xff08;请尊重原创&#xff0c;博主保留追究权&#xff09; https://blog.csdn.net/m0_69908381/article/details/131734299 出自【进步*于辰的博客】 因为我发现目前&#xff0c;我对Java-API的学习意识比较薄弱…

前端每周清单第 55 期: MobX 4 特性概览,iOS Hacks 分享, 分布式事务详解

前端每周清单第 55 期: MobX 4 特性概览&#xff0c;iOS Hacks 分享, 分布式事务详解 作者&#xff1a;王下邀月熊 编辑&#xff1a;徐川 前端每周清单专注大前端领域内容&#xff0c;以对外文资料的搜集为主&#xff0c;帮助开发者了解一周前端热点&#xff1b;分为新闻热点、…

iOS开发-AR初探

2019独角兽企业重金招聘Python工程师标准>>> 工具 Xcode9iOS 11新建工程 到这里&#xff0c;你什么都不需要做&#xff0c;启动项目就可以看见一架飞机。 关键词和关键类 关键词&#xff1a;场景视图&#xff0c;场景&#xff0c;几何&#xff0c;节点&#xff0c;渲…