1090 Highest Price in Supply Chain(29行代码+超详细注释)

这篇具有很好参考价值的文章主要介绍了1090 Highest Price in Supply Chain(29行代码+超详细注释)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

分数 25

全屏浏览题目

作者 CHEN, Yue

单位 浙江大学

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

代码长度限制

16 KB

时间限制

200 ms

内存限制

64 MB

#include<bits/stdc++.h>
using namespace std;
const int N=100010;
int n,root;
double p,r,res;
vector<int>v[N];//记录各节点的孩子节点
int cnt[N],maxh;//各层节点和最大深度
void dfs(int u,int h){
    if(v[u].size()==0){//是叶子结点 
        res=max(res,p*pow((1+r*1.0/100),h));//更新最大价格 
        cnt[h]++;//当前层的结点数+1 
        maxh=max(maxh,h);//记录最深的层数 
    }
    for(int i=0;i<v[u].size();i++){//深搜 
        dfs(v[u][i],h+1);
    }
}
int main(){
    cin>>n>>p>>r;
    for(int i=0;i<n;i++){//输入 
        int t;
        cin>>t;
        if(t==-1)root=i;
        else v[t].push_back(i);//t的孩子是i 
    }
    dfs(root,0);//深度遍历找到最深结点的价格和数量 
    printf("%.2f %d",res,cnt[maxh]);//输出价格和数量 
    return 0;
}
文章来源地址https://www.toymoban.com/news/detail-455263.html

到了这里,关于1090 Highest Price in Supply Chain(29行代码+超详细注释)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • MVSNet代码超详细注释(PyTorch)

    网上解读MVSNet的博客已经很多了,大家可以自选学习,但更重要的是阅读理解原文,以及自己动手跑跑代码! MVSNet服务器环境配置及测试 https://blog.csdn.net/qq_43307074/article/details/128011842 【论文简述及翻译】MVSNet:Depth Inference for Unstructured Multi-view Stereo(ECCV 2018) https://blog.csd

    2024年02月02日
    浏览(23)
  • DenseNet代码复现+超详细注释(PyTorch)

    DenseNet代码复现+超详细注释(PyTorch)

    关于DenseNet的原理和具体细节,可参见上篇解读:经典神经网络论文超详细解读(六)——DenseNet学习笔记(翻译+精读+代码复现) 接下来我们就来复现一下代码。 整个DenseNet模型主要包含三个核心细节结构,分别是 DenseLayer (整个模型最基础的原子单元,完成一次最基础的

    2023年04月23日
    浏览(9)
  • ResNet代码复现+超详细注释(PyTorch)

    ResNet代码复现+超详细注释(PyTorch)

    关于ResNet的原理和具体细节,可参见上篇解读:经典神经网络论文超详细解读(五)——ResNet(残差网络)学习笔记(翻译+精读+代码复现) 接下来我们就来复现一下代码。 源代码比较复杂,感兴趣的同学可以上官网学习:  https://github.com/pytorch/vision/tree/master/torchvision 本

    2024年02月11日
    浏览(17)
  • ResNeXt代码复现+超详细注释(PyTorch)

    ResNeXt代码复现+超详细注释(PyTorch)

    ResNeXt就是一种典型的混合模型,由基础的Inception+ResNet组合而成,本质在gruops分组卷积,核心创新点就是用一种平行堆叠相同拓扑结构的blocks代替原来 ResNet 的三层卷积的block,在不明显增加参数量级的情况下提升了模型的准确率,同时由于拓扑结构相同,超参数也减少了,便

    2024年02月15日
    浏览(14)
  • 【算法】顺时针打印矩阵(图文详解,代码详细注释

    【算法】顺时针打印矩阵(图文详解,代码详细注释

    目录 题目 代码如下: 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字。例如:如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则打印出数字:1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10 这一道题乍一看,没有包含任何复杂的数据结构和高级算法,似乎蛮简单的。但

    2024年04月26日
    浏览(9)
  • 1146 Topological Order(31行代码+详细注释)

    1146 Topological Order(31行代码+详细注释)

    分数 25 全屏浏览题目 作者 CHEN, Yue 单位 浙江大学 This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given directed graph? Now you are supposed to write a program to test each of the options. Input Specification: Each input file contains one test case. For each

    2024年02月06日
    浏览(30)
  • 非极大值抑制详细原理(NMS含代码及详细注释)

    非极大值抑制详细原理(NMS含代码及详细注释)

    作者主页: 爱笑的男孩。的博客_CSDN博客-深度学习,YOLO,活动领域博主 爱笑的男孩。擅长深度学习,YOLO,活动,等方面的知识,爱笑的男孩。关注算法,python,计算机视觉,图像处理,深度学习,pytorch,神经网络,opencv领域. https://blog.csdn.net/Code_and516?type=collect 个人介绍:打工人。 分享内容

    2023年04月21日
    浏览(8)
  • 五子棋小游戏 java版(代码+详细注释)

    五子棋小游戏 java版(代码+详细注释)

    游戏展示         这周闲来无事,再来写个五子棋小游戏。基本功能都实现了,包括人人对战、人机对战。界面布局和功能都写的还行,没做到很优秀,但也不算差。如有需要,做个java初学者的课程设计或者自己写着玩玩也都是不错的(非常简单,小白照着就能写出来)。

    2024年02月07日
    浏览(17)
  • 1063 Set Similarity(详细注释+35代码+set的妙用)

    分数 25 全屏浏览题目 作者 CHEN, Yue 单位 浙江大学 Given two sets of integers, the similarity of the sets is defined to be Nc​/Nt​×100%, where Nc​ is the number of distinct common numbers shared by the two sets, and Nt​ is the total number of distinct numbers in the two sets. Your job is to calculate the similarity of any give

    2024年02月05日
    浏览(9)
  • F#奇妙游(29):PPTX注释变音频插入页面

    天天学F#,感觉又没有动力了。还是要做点好玩点的、有用的东西才会更加有积极性。因为F#活在.NET平台中,做有用的东西简直太简单了。结合到最近知乎和别的平台一直在叽叽咕咕发视频,我没有怎么做过视频,但是PPT做得不少。我就想 为啥不能把PPT直接搞成视频呢? 这不

    2024年02月09日
    浏览(5)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包