首页 > 其他分享 >Highest Price in Supply Chain (25)

Highest Price in Supply Chain (25)

时间:2022-08-29 00:33:59浏览次数:59  
标签:25 dist chain int Price number supplier Highest price

题目描述

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.

输入描述:

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.

输出描述:

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.

输入例子:

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

输出例子:

1.85 2
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int dist[100005]={0};
 4 int number[100005];
 5 int main(){
 6     int n,root;
 7     float p,r;
 8     cin>>n>>p>>r;
 9     for(int i=0;i<n;++i){
10         cin>>number[i];
11     }
12     //对每一个结点进行回溯
13     for (int i=0;i<n;++i){
14         int temp=i;
15         while(number[temp]!=-1){
16             if (dist[number[temp]]>0){ //剪枝,如果该结点的父节点已确定高度则直接使用
17                 dist[i]+=dist[number[temp]]+1;
18                 break;
19             }
20             else{
21                 dist[i]++;
22                 temp=number[temp];
23             }
24         }
25     }
26     
27     int mmax=-1;
28     int count;
29     for (int i=0;i<n;++i){
30         if (mmax==dist[i]){
31             count++;
32         }
33         else if (mmax<dist[i]){
34             mmax=dist[i];
35             count=1;
36         }
37     }
38 
39     printf("%.2f %d",p*pow((100+r)/100,mmax),count);
40 }

题目乍一看不太容易理解,但本质上是一道通过回溯求叶子结点深度的问题,没啥细节,直接回溯就行了

标签:25,dist,chain,int,Price,number,supplier,Highest,price
From: https://www.cnblogs.com/coderhrz/p/16634569.html

相关文章

  • PAT Advanced 1029 Median(25)
    题目描述:GivenanincreasingsequenceSofNintegers,themedianisthenumberatthemiddleposition.Forexample,themedianofS1={11,12,13,14}is1......
  • leetcode刷题记录之25(集合实现)
    题目描述:给你链表的头节点head,每 k 个节点一组进行翻转,请你返回修改后的链表。k是一个正整数,它的值小于或等于链表的长度。如果节点总数不是 k 的整数倍,那么请将......
  • 25.伪善者
    迷雾偷走了颜色想扮演格外深刻寥寥几个人懂得眼看着就要一个人做选择割舍假意它动了声色犬马在适当玩乐无辜者掩饰什么玩命强撑着伪善的资格名额他情绪渐渐失控......
  • 825周总结
    目录前端一、前端与后端的概念二、前端的核心基础三、超文本传输协议1.四大特性2.数据格式3.响应状态码四、HTML1.简介2.语法3.head内常见标签4.body内部标签5.块级标签和......
  • Educational Codeforces Round 125 D
    D.ForGamers.ByGamers.最近又生病了然后就休息了两天人还真是休息不得直接寄掉了不管是手速还是思维啥的看到这道题很简单的一个变形都没看出来只看出了二分......
  • 1012 The Best Rank (25分)
    ToevaluatetheperformanceofourfirstyearCSmajoredstudents,weconsidertheirgradesofthreecoursesonly: C -CProgrammingLanguage, M -Mathemat......
  • 2022-08-25 第二小组 张鑫 学习笔记
    实训四十七天元素操作BOM1.学习内容自定义属性设置元素属性<divhaha="abc"id="xyz"></div><script>letdiv=document.querySelector("div");//......
  • WDA学习(25):DateNavigator使用
    1.18UIElement:DateNavigator使用本实例测试创建DateNavigator;1.创建Component,View:V_DATE_NAVIGATOR;2.创建Context节点;创建NODE:NODE_DATENAV,Cardinality:......
  • 洛谷 P2582 函数
    函数-洛谷可以发现性质\(g(f^m(x))=f^m(g(x))\)。若设左侧\(x\)所在环大小为\(size(x)\),右侧\(g(x)\)所在环的大小为\(size(gx)\)。可以得到,\(size(gx)\mid......
  • 2022-8-25 第四组 曹雨 Java script HTML元素操作,BOM
    对HTML元素的操作获取某个元素的属性的值:方法1:元素.属性名特别注意:元素.属性名的方式只适用于元素原生的属性,自定义的属性是拿不到的例子:console.log(div.id)方法2:......