Highest Price in Supply Chain (25)

2024-02-01 17:08
文章标签 25 chain supply highest price

本文主要是介绍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.
输入描述:
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.

16分做法:
思路:
直接用数组就行了,遍历每一个数组找到a[k]=-1,即就是找到根节点,然后用另一个数组记录每一个值,并维护最大值就可以了。当然会超时

#include<iostream>
#include<algorithm>
#include<algorithm>
using namespace std;
int n;
double p,r;
int a[100000];
int counts;
double maxn;
int k;
double nowcost[100000];
double currcost;
int main()
{cin>>n>>p>>r;
maxn=0;
r=1+0.01*r;for(int i=0;i<n;i++)cin>>a[i];for(int i=0;i<n;i++){k=i;currcost=p;while(a[k]!=-1)//找根的过程{k=a[k];
currcost*=r;if(a[k]==-1)break;}if(currcost>=maxn){maxn=currcost;}nowcost[i]=currcost;}for(int i=0;i<n;i++)if(nowcost[i]==maxn)counts++;printf("%.2lf",maxn);cout<<" ";
cout<<counts;return 0;
}

25分做法,bfs
vector二维数组数组模拟树搜下去就好了

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e5+5;
int n,root,anscnt=0;double p,r;
vector<int> G[maxn];
map<int,int> mp;void dfs(int cur,int step){int ok=1;for(int i=0;i<G[cur].size();++i){int v=G[cur][i];ok=0;dfs(v,step+1); }if(ok){if(step>anscnt){anscnt=step;++mp[anscnt];return ;}if(step==anscnt){++mp[anscnt];return ;}}
}
int main(){scanf("%d %lf %lf",&n,&p,&r);for(int i=0,tmp;i<n;++i){scanf("%d",&tmp);if(tmp==-1){ root=i;continue;}G[tmp].push_back(i);}dfs(root,0);    printf("%.2f %d\n",p*pow(1+r*0.01,anscnt),mp[anscnt]);return 0;
} 

这篇关于Highest Price in Supply Chain (25)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/667892

相关文章

【JavaScript】LeetCode:21-25

文章目录 21 最大子数组和22 合并区间23 轮转数组24 除自身以外数组的乘积25 缺失的第一个正数 21 最大子数组和 贪心 / 动态规划贪心:连续和(count)< 0时,放弃当前起点的连续和,将下一个数作为新起点,这里提供使用贪心算法解决本题的代码。动态规划:dp[i]:以nums[i]为结尾的最长连续子序列(子数组)和。 dp[i] = max(dp[i - 1]

Keysight U8031A DC power supply

Keysight U8031A DC power supply 文章目录 Keysight U8031A DC power supply前言电容充电⽰意图一、恒定电压操作二、恒定电流操作三、5v操作四、跟踪模式操作五、存储器操作六、对过电压保护编程七、对过电流保护编程八、锁键操作 前言 U8031A Power Supply 是一款具备前面板编程能力的三路输出电源。通过使

2025年25届计算机毕业设计:如何实现高校实验室Java SpringBoot教学管理系统

✍✍计算机毕业编程指导师** ⭐⭐个人介绍:自己非常喜欢研究技术问题!专业做Java、Python、微信小程序、安卓、大数据、爬虫、Golang、大屏等实战项目。 ⛽⛽实战项目:有源码或者技术上的问题欢迎在评论区一起讨论交流! ⚡⚡ Java、Python、微信小程序、大数据实战项目集 ⚡⚡文末获取源码 文章目录 ⚡⚡文末获取源码高校实验室教学管理系统-研究背景高校实验室教学管理系

webservice系列3---chain

本节摘要:本节主要介绍webservice的高级特性chain的开发和配置 1.引言       之前在上webservice系列2---javabean&handler中讲了handler的使用,当有多个handler的时候,难道我们要一个一个的在wsdd文件中配置,然后一个一个的引入到需要的webservice中码?of course ,no。Apache组织已经替我们考虑到了这种需求,ch

智力题:25匹马5条跑道找最快的3匹马,最少需要跑几次?

要找出25匹马中最快的3匹马,使用5条跑道,最少需要跑几次?我们可以通过逐步推理来解决这个问题。 第一步:分组比赛 首先,我们将25匹马分成5组,每组5匹马。每组进行一次比赛,这样我们就有5次比赛的结果。 组1:A1, A2, A3, A4, A5 组2:B1, B2, B3, B4, B5 组3:C1, C2, C3, C4, C5 组4:D1, D2, D3, D4, D5 组

芬兰手游业25年发展史

自2010年Rovio凭借《愤怒的小鸟》成功以来,芬兰的优秀开发者可以说是不断的引领手游潮流,有Frogmid、Seriously这样的小型团队,也有Supercell这样的世界收入冠军。除却收入之外,我们可以发现芬兰开发商的手游绝大多数都是具有独特创意的。 为什么芬兰手游业可以具有如此之大的竞争优势?其他人想要赶上应该怎么做?这个答案从来都不是能够简单作答的,因为它根植于芬兰的行业发展史,所以

设计模式 -- 职责链模式(Chain of Responsibility Pattern)

1 问题引出 1.1 学校 OA 系统的采购审批项目 如果金额 小于等于 5000, 由教学主任审批 (0<=x<=5000)如果金额 小于等于 10000, 由院长审批 (5000<x<=10000)如果金额 小于等于 30000, 由副校长审批 (10000<x<=30000)如果金额 超过 30000 以上,有校长审批 ( 30000<x) 1.2 传统方式 传统方式是

图形API学习工程(25):实现法线贴图

工程GIT地址:https://gitee.com/yaksue/yaksue-graphics 目标 在《图形API学习工程(10):基础光照》中,我实现了最基础的光照,同时也表现了法线的作用。 在《图形API学习工程(11):使用纹理》中,工程已经能够加载纹理贴图。 这样,法线贴图 所需的准备已经完成,可以在工程里实现这个技术了。 (关于法线贴图的意义,可见上一篇博客《从“法线贴图的意义

Flink 原理与实现:Operator Chain原理

硬刚大数据系列文章链接: 2021年从零到大数据专家的学习指南(全面升级版) 2021年从零到大数据专家面试篇之Hadoop/HDFS/Yarn篇 2021年从零到大数据专家面试篇之SparkSQL篇 2021年从零到大数据专家面试篇之消息队列篇 2021年从零到大数据专家面试篇之Spark篇 2021年从零到大数据专家面试篇之Hbase篇

【简历】25届南京某一本JAVA简历:简历通过率还好,但是拿不到OFFER

注:为保证用户信息安全,姓名和学校等信息已经进行同层次变更,内容部分细节也进行了部分隐藏 简历说明 今天看一份25届南京某一本大学的Java简历。 这个简历呢,学校是一本。我们说上来先要定校招层次,这个层次就按照中厂来讲。因为现在很多的双非一本目标都是在中厂。 这个同学有个实习经历,一本有八成的同学主项目都是重复的。HR他只能看到项目重不重复,要点对不对他不知道,就从这个角度来看,这位同学