Highest Price in Supply Chain (25)

news2024/9/19 10:34:40

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.coloradmin.cn/o/1482472.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

MYSQL--锁机制*

一.对锁机制的大概介绍: 1.大概的来说,MYSQL当中的锁实际上就是合理的管理多个服务器对于同一个共享资源的使用,是计算机协调多个进程或者是线程并发访问某一资源的机制(避免争抢资源的现象发生) 2.在数据库当中,数据是一种可以供许多的用户进行共享使用的资源,如何保证数据并发…

pclpy 点云法线

pclpy 点云法线 一、算法原理1.理论入门2.选择正确的比例 二、代码三、结果四、相关数据 一、算法原理 表面法线是几何表面的重要属性&#xff0c;在许多领域&#xff08;例如计算机图形应用程序&#xff09;中大量使用&#xff0c;以应用正确的光源来生成阴影和其他视觉效果。…

先进电机技术 —— 通用变频器

一、变频器名称定义 通用变频器&#xff08;Variable Frequency Drive, VFD&#xff09;是一种广泛应用于工业控制领域的电力电子设备&#xff0c;其主要功能是改变供电电源的频率和电压&#xff0c;以达到对交流电动机转速进行精确、连续调节的目的。通用变频器通常具备以下特…

2023年12月CCF-GESP编程能力等级认证Scratch图形化编程三级真题解析

一、单选题(共15题,共30分) 第1题 现代计算机是指电子计算机,它所基于的是( )体系结构。 A:艾伦图灵 B:冯诺依曼 C:阿塔纳索夫 D:埃克特-莫克利 答案:B 第2题 默认小猫角色,执行下列程序,舞台上会看到? ( ) A: B: C: D: 答案:C

数据库-第二/三章 关系数据库和标准语言SQL【期末复习|考研复习】

前言 总结整理不易&#xff0c;希望大家点赞收藏。 给大家整理了一下计数据库系统概论中的重点概念&#xff0c;以供大家期末复习和考研复习的时候使用。 参考资料是王珊老师和萨师煊老师的数据库系统概论(第五版)。 文章目录 前言第二、三章 关系数据库和标准语言SQL2.1 关系2…

Unity RectTransform·屏幕坐标转换

RectTransform转屏幕坐标 分两种情况 Canvas渲染模式为Overlay时&#xff0c;使用此方式 public Rect GetScreenCoordinatesOfCorners(RectTransform rt) {var worldCorners new Vector3[4];rt.GetWorldCorners(worldCorners);var result new Rect(worldCorners[0].x,world…

Redis--持久化机制详解

什么是redis持久化&#xff1f; Redis持久化是将内存的数据持久化到磁盘上&#xff0c;防止Redis宕机或者断点的时候内存中的数据丢失&#xff0c;把内存中的数据写入到磁盘的过程叫持久化。 Redis持久化的方式&#xff1f; RDB&#xff08;Redis DataBase&#xff09;&…

无法调试MFC源码

VS无法调试MFC源码 起初 有时候就是这么无奈&#xff0c;MFC源码各种问题没有办法调试&#xff0c;可是又想看下代码如何调用&#xff0c;里面做了些什么&#xff0c;从哪儿调出&#xff0c;学习一下大神的思路什么的。整理一下有可能的原因。 检查生成代码设置 需要设置正…

echarts vue 动画效果的水球图、波浪图教程

1、安装插件 前提是已经安装了echarts&#xff08;我的版本是4.2.1&#xff09; npm install echarts-liquidfill --save 我安装了3.1.0版本的&#xff0c;结果运行时报错"TypeError: wave.ensureState is not a function" 原因&#xff1a;echarts版本和echarts-l…

每周一算法:双端队列广搜

题目链接 电路维修 题目描述 达达是来自异世界的魔女&#xff0c;她在漫无目的地四处漂流的时候&#xff0c;遇到了善良的少女翰翰&#xff0c;从而被收留在地球上。翰翰的家里有一辆飞行车。有一天飞行车的电路板突然出现了故障&#xff0c;导致无法启动。 电路板的整体结…

JavaSE——常用API(2/3)-String使用时的注意事项、String的应用案例

目录 String使用时的注意事项 阅读程序并解答&#xff08;1&#xff09; 阅读程序并解答&#xff08;2&#xff09; String的应用案例 案例1 案例2 小结 String使用时的注意事项 String对象的内容不可改变&#xff0c;被称为不可变字符串对象。&#xff08;每次试图改变…

软考 系统分析师系列知识点之需求获取(7)

所属章节&#xff1a; 第11章. 软件需求工程 第2节. 需求获取 需求获取是一个确定和理解不同的项目干系人的需求和约束的过程。需求获取是一件看上去很简单、做起来却很难的事情。需求获取是否科学、准备是否充分&#xff0c;对获取出来的结果影响很大&#xff0c;这是因为大部…

每日学习总结20240228

每日总结 20240228 1.获取系统命令执行结果 #include <stdio.h>#define TRUE 1 #define FALSE 0int get_system_cmd_result(const char *command, char *buffer, int bufferLen) {FILE *pipe popen(command, "r");if (pipe NULL) {return FALSE;}while (f…

winform 自定义组件 之踩坑 自定义属性属性列表不展示

问题描述&#xff1a; 使用winform 自定义组件&#xff0c;定义自定义属性性&#xff0c; 使用自定义组件属性页面不展示。 百度N次无解 问了AI 发现犯了个低智错误&#xff1a; 属性末设置为 public; 解决方案一&#xff1a;

NLP Seq2Seq模型

&#x1f368; 本文为[&#x1f517;365天深度学习训练营学习记录博客&#x1f366; 参考文章&#xff1a;365天深度学习训练营&#x1f356; 原作者&#xff1a;[K同学啊 | 接辅导、项目定制]\n&#x1f680; 文章来源&#xff1a;[K同学的学习圈子](https://www.yuque.com/mi…

等概率事件算法

1等概率的生成(0-8)范围内的正整数 // Math.random 数据范围[0,1) 且 是 等概率的产生随机数 // 应用&#xff1a; // 1.生成等概率的整数&#xff08;等概率的生成(0-8)范围内的正整数 int value (int) (Math.random() * 9); System.out.println("value "…

YOLOv9有效提点|加入BAM、CloFormer、Reversible Column Networks、Lskblock等几十种注意力机制(二)

专栏介绍&#xff1a;YOLOv9改进系列 | 包含深度学习最新创新&#xff0c;主力高效涨点&#xff01;&#xff01;&#xff01; 一、本文介绍 本文只有代码及注意力模块简介&#xff0c;YOLOv9中的添加教程&#xff1a;可以看这篇文章。 YOLOv9有效提点|加入SE、CBAM、ECA、SimA…

逆变器专题(13)-逆变器LCL滤波器设计

相应仿真原件请移步资源下载 随着新能源的蓬勃发展&#xff0c;逆变器作为光伏储能的核心电力电子器件之一&#xff0c;其也得到了大力发展&#xff1b;传统的L型以及LC型滤波器因其体积较大、滤波效果差等原因已经被逐渐替代&#xff0c; LCL滤波器因其具有较小的体积&#xf…

JavaWeb HTTP 请求头、请求体、响应头、响应体、响应状态码

J2EE&#xff08;Java 2 Platform Enterprise Edition&#xff09;是指“Java 2企业版”&#xff0c;B/S模式开发Web应用就是J2EE最核心的功能。 Web是全球广域网&#xff0c;也称为万维网(www)&#xff0c;能够通过浏览器访问的网站。 在日常的生活中&#xff0c;经常会使用…

通过GitHub探索Python爬虫技术

1.检索爬取内容案例。 2.找到最近更新的。(最新一般都可以直接运行) 3.选择适合自己的项目&#xff0c;目前测试下面画红圈的是可行的。 4.方便大家查看就把代码粘贴出来了。 #图中画圈一代码 import requests import os import rewhile True:music_id input("请输入歌曲…