Highest Price in Supply Chain (25)

1、题目:

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

2、24分思路:

将该问题看成最长路处理,每条有向边的权重都是1 + r/100,求出最长的那个,并统计有多少条最长路。

有一个点过不去,无语死了

代码如下:

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;
const double eps = 1e-8;
int h[N],e[2*N],ne[2*N],idx;
double w[2*N];double dist[N];
ll cntdist[N];
bool st[N];
int n;
double p,r,maxx=-2e9;
ll cnt = 0;
void add(int a,int b,double c)
{e[idx] = b,ne[idx] = h[a],w[idx] = c,h[a] = idx++;
}
void spfa(int x)
{memset(dist,-0x3f,sizeof dist);queue<int> q;dist[x] = p;cntdist[x] = 1;q.push(x);while(q.size()){int t = q.front();q.pop();for(int i = h[t];~i;i = ne[i]){int j = e[i];if(dist[j] < dist[t] * w[i]){dist[j] = dist[t] * w[i];q.push(j);maxx = max(maxx,dist[j]);cntdist[j] = cntdist[t];}else if(abs(dist[j]-dist[t]*w[i])<=eps){cntdist[j] += cntdist[t];}}}
}
int main()
{std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);memset(h,-1,sizeof h);cin>>n>>p>>r;int sta = 0;// 初始节点 if(n==1){cout<<p<<endl;return 0;}for(int i = 0;i<n;i++){int supply;cin>>supply;if(supply!=-1)add(supply,i,1.0 + r/100);else sta = i;}spfa(sta);for(int i = 0;i<n;i++){if(abs(maxx-dist[i])<=eps){cnt += cntdist[i];}}cout<<fixed<<setprecision(2)<<maxx-1e-6<<" "<<cnt;return 0;
}

3、满分思路

用的是深搜,搜索最长距离,如果有更长,就更新,并把数量置为1,如果相等,数量++。

这个思路不错,我参考其他人的题解的,学到了怎么求深度哈哈哈

 代码如下:

#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
const int N = 1e5 + 10;
int n,maxdepth = 0,maxnum = 0,temp,root;
vector<int> v[N];void dfs(int index,int depth)
{if(v[index].size()==0)// 叶子节点 {if(maxdepth == depth)maxnum++;if(maxdepth<depth){maxdepth = depth;maxnum = 1; }return;	}for(int i = 0;i<v[index].size();i++)dfs(v[index][i],depth + 1);
}int main()
{double p,r;scanf("%d%lf%lf",&n,&p,&r);for(int i = 0;i<n;i++){scanf("%d",&temp);if(temp==-1)root = i;else v[temp].push_back(i);}dfs(root,0);printf("%.2lf %d",p*pow(1.0 + r/100,maxdepth),maxnum);return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/502626.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Spring MVC 和 Spring Cloud Gateway不兼容性问题

当启动SpringCloudGateway网关服务的时候&#xff0c;没注意好依赖问题&#xff0c;出现了这个问题&#xff1a; Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway. 解决办法就是&#xff1a;删除SpringMVC的依赖&#xff0c;即下列依赖。 &…

蓝桥杯练习系统(算法训练)ALGO-996 车的放置

资源限制 内存限制&#xff1a;256.0MB C/C时间限制&#xff1a;1.0s Java时间限制&#xff1a;3.0s Python时间限制&#xff1a;5.0s 问题描述 在一个n*n的棋盘中&#xff0c;每个格子中至多放置一个车&#xff0c;且要保证任何两个车都不能相互攻击&#xff0c;有多少…

深入探究Python多进程编程:Multiprocessing模块基础与实战【第98篇—Multiprocessing模块】

深入探究Python多进程编程&#xff1a;Multiprocessing模块基础与实战 在Python编程中&#xff0c;多进程处理是一项关键的技术&#xff0c;特别是在需要处理大规模数据或执行耗时任务时。为了充分利用多核处理器的优势&#xff0c;Python提供了multiprocessing模块&#xff0…

MYSQL02高级_目录结构、默认数据库、表文件、系统独立表空间

文章目录 ①. MySQL目录结构②. 查看默认数据库③. MYSQL5.7和8表文件③. 系统、独立表空间 ①. MySQL目录结构 ①. 如何查看关联mysql目录 [rootmysql8 ~]# find / -name mysql /var/lib/mysql /var/lib/mysql/mysql /etc/selinux/targeted/tmp/modules/100/mysql /etc/seli…

2024年新提出的算法|LEA爱情进化算法(Love Evolution Algorithm)

Love Evolution Algorithm: a stimulus–value–role theory-inspired evolutionary algorithm for global optimization 爱情进化算法Love Evolution Algorithm&#xff0c;LEA&#xff0c;于2024年2月发表在中科院3区SCI期刊 The Journal of Supercomputing。 1、简介 本文提…

13.网络游戏逆向分析与漏洞攻防-网络通信数据包分析工具-如果没有工具就创造工具

内容参考于&#xff1a; 易道云信息技术研究院VIP课 上一个内容 &#xff1a;12.游戏网络通信存在的问题 现在把游戏网络的架构看了一个小小的大概&#xff0c;可以用它的接口发数据接收数据了&#xff0c;如果真正想用它这一套东西&#xff0c;真正核心不在于它的接口而在于…

(介绍与使用)物联网NodeMCUESP8266(ESP-12F)连接新版onenet mqtt协议实现上传数据(温湿度)和下发指令(控制LED灯)

前言 本文详细介绍了如何利用物联网技术,通过NodeMCU ESP8266(ESP-12F)模块连接到新版的OneNet平台,使用MQTT协议实现数据的上传与指令的下发。文中首先对NodeMCU ESP8266模块及其特性进行了简介,随后详细阐述了如何配置和使用MQTT协议连接到OneNet平台,实现温湿度数据的…

华宽通招商合同履约管理系统:全流程把控,引领招商引资新篇章

在当今高速发展的经济时代&#xff0c;招商活动已成为推动产业园区发展的重要引擎。然而面对复杂多变的市场环境&#xff0c;传统的招商方式已无法满足现代产业园区的高效管理需求。华宽通招商合同履约管理系统应运而生&#xff0c;旨在通过科技手段&#xff0c;为招商引资提供…

外包干了7个月,技术退步明显.......

先说一下自己的情况&#xff0c;大专生&#xff0c;18年通过校招进入北京某软件公司&#xff0c;干了接近4年的功能测试&#xff0c;今年年初&#xff0c;感觉自己不能够在这样下去了&#xff0c;长时间呆在一个舒适的环境会让一个人堕落! 而我已经在一个企业干了四年的功能测…

Qt应用软件【测试篇】vargrid内存检查工具

文章目录 vargrid介绍vargrid官网vargrid安装常用命令Valgrind的主要命令vargrid介绍 Valgrind是一个用于构建动态分析工具的框架,能自动检测许多内存管理和线程错误,并详细分析程序性能。Valgrind发行版包括七个成熟工具:内存错误检测器、两个线程错误检测器、缓存和分支预…

数通HCIE和云计算HCIE哪个好一点?

数通是网络的基础知识&#xff0c;也是入门人员必学的方向&#xff0c;相对也会简单些&#xff0c;学习数通&#xff0c;可以很好的学习其他的方向。数通的就业范围也比较广&#xff0c;运营商、企业、政府还是互联网公司&#xff0c;都需要大量的数通工程师来搭建和维护网络&a…

qt cmake添加resource文件

文章目录 方式一:方式二:qrc的使用 两种方式 方式一: 创建一个qrc文件&#xff0c;在qt_add_executable 中直接添加 qt_add_executable(helloworldmain.cppimageresources.qrc )方式二: 使用 qt_add_resources qt_add_resources(helloworld "app_images"PREFIX &…