1090 Highest Price in Supply Chain (25 point(s))

PAT甲级 1090 Highest Price in Supply Chain A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer. 阅读详情

1090 Highest Price in Supply Chain (25 point(s))

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 (≤10​5​​), 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 S​i​​ is the index of the supplier for the i-th member. S​root​​ 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 10​10​​.

Sample Input:

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

Sample Output:

1.85 2

考察点:图论DFS、树的深度

本质考察树的深度。看到它给出数据的方式,第一反应是直接用找根节点的findRoot()函数的递归次数,可以找到该节点的层次。思路是正确的,但是也果不其然地TLE了。

然后用常规方法,使用DFS,还是采用vector<int>graph[N]建立树,用level[]记录每个结点所在层次,方便在最后计算最深的结点的个数。

也可以用BFS完成。大神链接:https://blog.youkuaiyun.com/richenyunqi/article/details/80146351

第一反应代码(3个用例出现TLE,16分):

#include<iostream>
using namespace std;
const int N = 1e5+7;
int Tree[N];
int cnt,depth = 0;
int findRoot(int x){
	cnt++;
	if(Tree[x]==-1) return x;
	else return findRoot(Tree[x]);
}
int main(void){
	int n;double p,rate;
	cin>>n>>p>>rate;
	for(int i=0;i<n;i++) cin>>Tree[i];
	int num = 0;
	for(int i=0;i<n;i++){
		cnt = 0;
		findRoot(i);
		if(cnt>depth){
			depth=cnt;
			num = 1;
		}
		else if(cnt==depth){
			num++;
		}
	}
	for(int i=0;i<depth-1;i++){
		p = p *(1.00+0.01*rate);
	}
	printf("%.2f %d\n",p,num);
	return 0;
}

AC代码:

#include<iostream>
#include<vector>
using namespace std;
const int N = 1e5+7;
vector<int> graph[N];
int level[N];
void dfs(int v){
	for(int i=0;i<graph[v].size();i++){
		int cur = graph[v][i];
		level[cur] = level[v]+1;
		dfs(cur);
	}
}
int main(void){
	int n;double p,rate;
	cin>>n>>p>>rate;
	int a,root;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a==-1) root = i;
		else{
			graph[a].push_back(i);
		} 
	} 
	level[root]=0;
	dfs(root);
	int depth=0,cnt = 0;
	for(int i=0;i<n;i++){
		if(level[i]>depth){
			depth = level[i];
			cnt = 1;
		}else if(level[i]==depth) cnt++;
	}
	for(int i=0;i<depth;i++){
		p = p *(1.00+0.01*rate);
	}
	printf("%.2f %d\n",p,cnt);
	return 0;
}

RTKlib操作手册--使用样例数据演示 本文将使用样例数据演示如何使用RTKLIB进行rtk差分定位。 阅读详情

相关推荐

HybridCLR热更新打包报错全解析:从原理到实战解决方案

热更新技术是现代游戏和应用开发中实现动态内容交付与Bug修复的核心机制,它允许开发者在无需重新发布完整应用的情况下更新代码逻辑。其原理通常涉及在运行时加载并执行新的代码模块,这要求框架在底层实现安全的代码隔离、内存管理与元数据桥接。在Unity生态中,HybridCLR作为基于IL2CPP的高性能热更新解决方案,通过补充元数据和AOT泛型引用技术,实现了对C#代码的原生级热更支持,显著提升了开发迭代效率与线上问题修复能力。然而,在实际的工程实践中,尤其是在面向Android、iOS等多平台打包构建时,开发者

weixin_29017445的博客 308

【PAT甲级A1090】Highest Price in Supply Chain (25分)(c++)

1090 Highest Price in Supply Chain (25分) 作者:CHEN, Yue 单位:浙江大学 代码长度限制:16 KB 时间限制:200 ms 内存限制:64 MB A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer. Start

小庄同学的博客 225

vivado 编译ADI AD9361 TCL脚本生成hdl工程

(4)输入"source ../../scripts/adi_make.tcl"命令(仅双引号内部命令,不包含双引号),个人理解:该命令用来加载当前所需要编译工程所需要各功能模块的信息,因为每个工程需要不同的功能模块,比如有的需要gpio模块,有的不需要gpio模块,这些模块上前面路径的library也同样以TCL脚本形式存在,当有需要时才进行编译,怎么知道当前工程需要什么模块呢就是通过"source ../../scripts/adi_make.tcl"(仅双引号内部命令,不包含双引号)命令实现。

weixin_40586423的博客 807

1090 Highest Price in Supply Chain (25 分) 全网最细 题目详解 翻译 完整代码 PAT甲级真题解析

1090 Highest Price in Supply Chain(25分)预备知识:题目翻译:输入格式:输出格式:题目解析:逻辑梳理:参考代码: 预备知识: 二叉树的深度优先搜索 题目翻译: 供应链是一个由零售商、经销商和供应商构成的网络,负责将产品从供应商转移到客户手中。 从一个根供应商开始,供应链上的每个人都以P的价格从供应商那里购买产品,然后以比P高r%的价格销售或分销。假设供应链中的每个成员除了根供应商外只有一个供应商(每个结点只有一个父结点),并且没有供应环(树中没有环路)。现在给你一个

BBBling的博客 574

Postman调试海康ISAPI接口全记录:从鉴权失败到成功修改设备名的踩坑指南

本文详细记录了使用Postman调试海康ISAPI接口的全过程,从鉴权失败到成功修改设备名的实战经验。涵盖Digest认证机制、XML请求体构造、常见错误排查及代码实现过渡,帮助开发者高效解决海康设备集成中的各种问题。

weixin_42620913的博客 660

2024.6.10丨基于DIAMOND与VFDB数据库的致病菌毒力因子高效注释指南

本文详细介绍了基于DIAMOND与VFDB数据库的致病菌毒力因子高效注释方法,涵盖工具安装、参数优化、数据库选择及实战案例解析。通过DIAMOND的快速比对和VFDB的全面毒力因子数据,显著提升微生物基因组研究效率,适用于临床检测、食品安全监测等多个场景。

weixin_33712987的博客 375

PAT 甲级 1090  Highest Price in Supply Chain

1090 Highest Price in Supply Chain (25 point(s)) A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer...

漫浸天空的雨色的备忘录~ 885

逆向解析抖音核心校验参数:bd-ticket-guard-client-data的Python生成逻辑

本文深入解析了抖音核心校验参数bd-ticket-guard-client-data的生成逻辑,详细介绍了其动态证书生成、非对称加密机制及Python实现方法。通过逆向分析,揭示了抖音安全体系的双层验证机制,包括RSA密钥对生成、证书签名及时间戳校验等关键技术要点,为开发者提供了一套完整的参数生成解决方案。

weixin_26642481的博客 404

【PAT甲级 - C++题解】1090 Highest Price in Supply Chain

📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!

Newin2020的博客 669

SDMA 如何实现设备对主机内存的访问

摘要:SDMA(System Direct Memory Access)是PCIe设备直接访问主机内存的核心机制,使外设无需CPU干预即可高效读写系统RAM。其实现原理包括:设备作为主控发起DMA请求,通过PCIe Memory TLP访问主机物理地址;完整通路涉及驱动分配DMA安全内存、设备配置、地址转换(IOMMU)和中断通知等步骤;关键技术涵盖地址类型(HPA/IOVA)、TLP格式、缓存一致性和安全防护机制。SDMA广泛应用于GPU、网卡、NVMe等高性能场景,是现代异构计算的基础技术,需软硬件协同

MHD0815的博客 239

【干货】SAP特殊库存:Q库存(项目库存)全解析,搞懂ETO模式的核心!

在 SAP 系统中,

我小时候很黑的博客 901

1090 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 an

naexting的博客 255

一点击打印电脑就卡死?资源管理器停止工作的解决方法

Windows11共享的HP1022n打印机导致客户端打印时资源管理器崩溃卡死,电脑停止工作。

gary18的专栏 577

1090 Highest Price in Supply Chain (25 point(s))

matter 不行以后都换成double类型的数据。。。 2.模板:利用DFS求树的深度。 code #include<iostream> #include<vector> #include<cmath> using namespace std; const int MAXN = 100010; vector<int> child[MAX...

Bonstoppo 274

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

PAT A1090 Highest Price in Supply Chain (25point(s))

题目链接 思路:本题的本质就是求树的最大深度及最大深度叶子结点的个数,可以用一个递归算法求每一个深度点的,孩子结点深度是双亲结点深度加1,本题右给出了每个结点双亲结点的下标,故可以利用这个关系进行递归,每一个结点都可以向上追溯到根节点,因此遇到根节点即是递归出口,且根节点的深度为1。为避免重复计算,可以用一个level[100010]数组去保存每一个结点的深度,这样不是每一个结点都需要递归到根节点...

皮皮瓜的博客 217

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

1090 Highest Price in Supply Chain (25point(s))

1090 Highest Price in Supply Chain (25point(s)) 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 b

佳迪斯的博客 184

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

1090 Highest Price in Supply Chain (25 point(s))

题解 dfs. #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;algorithm&gt; #include&lt;vector&gt; #include&lt;cmath&gt; using namespace std; int maxdepth, maxnum; vector&lt;vector&lt;int&g...

徐伯莱 254

1090 Highest Price in Supply Chain (25point(s)) - C语言 PAT 甲级

价格仅和叶节点层数有关,所以利用并查集的思想,记录每个节点的父节点,以递推出叶节点的层数 * level[v] = get_level(father[v]) + 1,要用数组 level 记录层级信息,不记录的话每次都查询到根节点,会超时 * 根节点 level[0] = 0 * 注意根节点是 -1 表示的,查询根节点 0 的层数时会询问 -1 节点,此时把 -1 节点看作根节点的父节点,返回 -1

有三只土豆 233

1090 Highest Price in Supply Chain (25 point(s)) PAT甲级

1090 Highest Price in Supply Chain (25 point(s)) DFS 题目 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

neko的博客 190

PAT(甲级)1090 Highest Price in Supply Chain (25point(s))

题目 题目链接 思路 跟 1079 类似,但是要注意根节点不一定是 0 号节点; 代码 #include <iostream> #include <vector> #include <stack> #include <queue> #include <algorithm> #include <cstring> #include <string> #include <math.h> using namespace

hjyp的博客 137

PAT_甲级_1090 Highest Price in Supply Chain (25point(s)) (C++)【DFS】

目录 1,题目描述 题目大意 2,思路 3,AC代码 4,解题过程 1,题目描述 Sample Input: 9 1.80 1.00 1 5 4 4 -1 4 5 3 6 Sample Output: 1.85 2 题目大意 求一个供应链中,货物可以卖出的最高价,以及卖出最高价的零售商数目 each number S​i​​ is the index ...

&再见萤火虫&的博客 322

1090. Highest Price in Supply Chain (25)-PAT甲级真题

1090. 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. Sta

柳婼 の blog 2202

PAT甲级 1090 Highest Price in Supply Chain (25 分)

题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805376476626944 思路:直接存图dfs即可 代码: #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; vector <int> ...

一只谜谜怪的博客 334

1090 Highest Price in Supply Chain (25分)

1 题目 1090 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. St...

韩江雪de 小屋 533
上一篇: 1091 Acute Stroke (30 point(s))
下一篇: 1030 Travel Plan (30 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值