1106 Lowest Price in Supply Chain (25 point(s))

PAT甲级 1106 Lowest 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. 阅读详情

1106 Lowest 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. Only the retailers will face the customers. 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 lowest price a customer 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 their ID's are numbered from 0 to N−1, and the root supplier's ID is 0); P, the price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then N lines follow, each describes a distributor or retailer in the following format:

K​i​​ ID[1] ID[2] ... ID[K​i​​]

where in the i-th line, K​i​​ is the total number of distributors or retailers who receive products from supplier i, and is then followed by the ID's of these distributors or retailers. K​j​​ being 0 means that the j-th member is a retailer. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print in one line the lowest price we can expect from some retailers, accurate up to 4 decimal places, and the number of retailers that sell at the lowest price. There must be one space between the two numbers. It is guaranteed that the all the prices will not exceed 10​10​​.

Sample Input:

10 1.80 1.00
3 2 3 5
1 9
1 4
1 7
0
2 6 1
1 8
0
0
0

Sample Output:

1.8362 2

问题的本质:求树的叶子节点的最低层次及其个数。

思路:

1. 存储树的结构(注意到这是有向树)。注意根据输入标记叶子结点。

2. 采用BFS方式遍历整棵树,求出每一个结点的层次。

3. 根据1的标记,求出叶子节点的最低层次,并累计个数。

同时参考1079 Total Sales of Supply Chain和1090 Highest Price in Supply Chain。

也可以用DFS求解。

参考链接:https://blog.youkuaiyun.com/richenyunqi/article/details/80152791

#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
#include<cmath>
#define INF 0x3f3f3f3f
using namespace std;
const int MAX = 1e5+7;
vector<int> graph[MAX];
int level[MAX];
bool isRetailer[MAX]={false};
int minLevel = INF;
void bfs(int root){//BFS求出每一个结点的层次,并求出叶子节点的最低层次 
	queue<int> q;
	q.push(root);
	level[root]=0;
	while(!q.empty()){
		int top = q.front();
		q.pop();
		if(isRetailer[top]){//如果这是一个叶子节点 
			minLevel=min(minLevel,level[top]);
		}
		for(int i=0;i<graph[top].size();i++){//否则遍历这些节点,更新它们的层次,并加入队列 
			int cur = graph[top][i];
			level[cur]=level[top]+1;
			q.push(cur);
		}
	}
}
int main(void){
	int N,K,a;double p,r;
	cin>>N>>p>>r;
	for(int i=0;i<N;i++){
		cin>>K;
		if(K==0) isRetailer[i]=true;
		while(K--){
			cin>>a;
			graph[i].push_back(a);
		}
	}
	int root = 0;
	bfs(root);
	int cnt =0;
	for(int i=0;i<N;i++){
		if(isRetailer[i]&&level[i]==minLevel) cnt++;
	}
	printf("%.4f %d",p*pow((1+0.01*r),minLevel),cnt);
}

 

2026.3.10:最新claude code完美解决方案,跳过登录界面,使用国内deepseek-v4-pro进行计费 本文介绍了一种绕过Claude登录界面直接使用国内DeepSeek-V4-Pro服务的解决方案。通过npm全局安装@anthropic-ai/claude-code包,并配置5个关键环境变量:API认证令牌、基础URL(指向DeepSeek服务)、指定模型为deepseek-v4-pro、禁用非必要流量等。文中提供了4张配图辅助说明配置过程,但未展示具体内容。该方案可实现直接计费使用,无需通过官方登录流程。 阅读详情

相关推荐

CPU系统级验证——测试激励——imperas公司riscvOVPsimPlus文件分析

本分析重点关注该repo向量扩展部分。 1. repo简介 该repo是指令集验证的仿真环境包括,大部分是指令集的测试用例,也包含了一些模拟器,如riscvOVPsimPlus。 主要介绍的是riscvOVPsimPlus指令集模拟器,riscvOVPsimPlus(下面统称ISS)是imperas公司在riscvOVPsim基础上扩充了向量扩展的指令集模拟器,该repo于今年9月份部分开源 什么叫部分开源呢? 首先该repo必须在imperas官网注册下载,而且必须是企业用户(免费邮箱人家瞧不上.

知识,既贵,又便宜。 4460

1106 Lowest 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 th...

张蔡辉 226

MTK-AWB 小结 (二)

调试总结:可以将offset 对应的ratio加大,保留更多的喜好色(偏色),影响WF statistic gain,从而影响最终的awb gain。这一部分前期CCT校准的时候就会算出一组默认值,当然这个offset offse 值用于优化T,S,wf 光下的偏色喜好度. offset。后面遇到 A H Shad 光收白或者偏色,还可以优化 A 的offset ,H offset,shad offset.new offset 计算过程(Day locus offset 和M/G offset )

qq_46056347的博客 1168

1106 Lowest Price in Supply Chain (25 point(s))

#include&lt;cstdio&gt; #include&lt;vector&gt; #include&lt;iostream&gt; #include&lt;cmath&gt; using namespace std; const int INF = 0x3f3f3f3f; int mindepth = INF, maxnum; int n, k; double p, r; vect...

徐伯莱 237

东方财富个股实时行情爬虫实战:从入门到精通,手把手教你构建股票数据采集系统

在量化投资、股市分析和数据挖掘等领域,获取实时、准确的股票行情数据是第一步也是至关重要的一步。东方财富网作为国内最大的财经门户网站之一,提供了丰富的股票数据和实时行情接口。本文将带你从零开始,构建一个完整的东方财富个股实时行情爬虫系统,涵盖股票代码遍历、JSON接口分析、反爬虫策略应对、数据持久化存储等核心技术点。目录前言一、项目背景与目标1.1 为什么要爬取东方财富数据?1.2 项目目标1.3 技术栈二、接口分析与逆向工程2.1 寻找真实数据接口2.2 简化接口2.3 字段含义对照表三、股票代码获取。

2201_76125261的博客 147

【YOLO26创新改进】TGRS 2026 | Transformer变体改进篇 | 使用CGTA曲率引导令牌注意力,改善结构与纹理的整体协调,适合遥感小目标检测、旋转目标检测、实例分割任务

本文在YOLO26目标检测模型中引入CGTA曲率引导令牌注意力模块,依据曲率显著性与特征可靠性,从高分辨率特征图中筛选少量关键令牌,再让全部位置与这些代表性特征进行全局交互,从而以较低计算和显存开销建立远距离目标、背景及跨尺度结构之间的联系;该模块能够重点强化车辆、舰船、飞机、建筑等目标的边缘、转角和弯曲轮廓,改善小目标、密集目标及旋转目标的特征完整性与定位稳定性,并通过可靠性门控抑制噪声和伪边缘,通过标准注意力与曲率注意力融合避免平坦区域被过度增强。

AI魔改博士-中大博士 47

1106 Lowest Price in Supply Chain (25point(s))

1106 Lowest 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 bu

佳迪斯的博客 171

vscode配置matlab工作环境

前面有两篇文章我们分别讲了在vscode里面如何配置C语言环境和python环境,那两篇文章总体来说比较复杂,当然这篇也有许多有趣的问题。 附上链接: 文章目录matlab简介基本要求code runner插件与matlab相关的插件添加路径小结code runner是否支持更多语言更多选择另一个选择 matlab简介 MATLAB是美国MathWorks公司出品的商业数学软件,用于数据分析、无线通信、深度学习、图像处理与计算机视觉、信号处理、量化金融与风险管理、机器人,控制系统等领域。 MATLAB是ma

Cachel Wood的博客 4541

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

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

有三只土豆 577

华为OD机考双机位C卷 - 评委评分 (Java & Python& JS & C/C++ & GO )

华为OD机考双机位C卷 - 评委评分 (OD上机考试双机位C卷)。提供在线OJ刷题。Java、C++、Python、GO语言、C语言、JavaScript题解,并提供完整思路讲解。

算法大师! 1750

SAP Clean Core 对传统 ABAP 开发人员来说意味着什么:机遇和挑战

SAP Clean Core是一种战略方法,旨在优化和现代化 SAP S/4HANA 系统,通过尽量减少定制,确保核心系统的稳定性、高效性和对云环境的兼容性。Clean Core 作为一种设计思路,致力于让 ERP 系统的核心功能保持简洁、规范,避免不必要的复杂化,最终维持一个标准化的核心,使系统更容易升级、性能更优越,同时支持快速的创新能力。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 611

PAT(甲级)1106 Lowest Price in Supply Chain (25point(s))

题目 题目链接 思路 题目大意:找到最便宜的零售商以及这样零售商的数量,也就是最早出现叶节点的那一层中叶节点个数; 最好用BFS,可以不用全部遍历,比较高效,也可以用DFS,但是需要全部遍历一遍; 一层层的遍历,遍历每一层时设置一个布尔值,用来判断这层有没有叶节点,如果出现叶节点,那么在遍历完这层后就应该结束迭代; 为什么不是一找到叶节点就结束迭代,因为需要统计这层叶节点的个数; 代码 #include <iostream> #include <vector> #include &l

hjyp的博客 243

15、电科院FTU检测标准学习笔记-基本性能

作者简介:本人从事电力系统多年,岗位包含研发,测试,工程等,具有丰富的经验在配电自动化验收测试以及电科院测试中,本人全程参与,积累了不少现场的经验。

sixtome 1865

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

目录 1,题目描述 题目大意 2,思路 3,AC代码 4,解题过程 1,题目描述 Sample Input: 10 1.80 1.00 3 2 3 5 1 9 1 4 1 7 0 2 6 1 1 8 0 0 0 Sample Output: 1.8362 2 题目大意 在供应链形成的过程中,每经过一个节点,价格增长一定的百分比,输出售价最小的价格,以及以此价...

&再见萤火虫&的博客 273

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

PAT----A1106 Lowest Price in Supply Chain (25point(s))

A1106 Lowest Price in Supply Chain (25point(s)) 题意: 寻找最小深度的叶子节点并统计个数 Sample Input 10 1.80 1.00 3 2 3 5 1 9 1 4 1 7 0 2 6 1 1 8 0 0 0 Sample Output 1.8362 2 #include"bits/stdc++.h" using namespace st...

qq_43578870的博客 138

蓝牙模块HM-10手册

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

PAT(A)1106 Lowest Price in Supply Chain (25point(s))(深度优先搜索)

Sample Input 10 1.80 1.00 3 2 3 5 1 9 1 4 1 7 0 2 6 1 1 8 0 0 0 Sample Output 1.8362 2 思路: 最快乐就是看到全AC,和前面有一道题几乎一模一样,就是深搜求最小深度,然后统计同深度的叶子数目。开始没看到是同一棵树,还以为是森林。。。审题很重要!!! 代码 #include <bits/stdc+...

Sqssq的博客 173

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

1106 Lowest Price in Supply Chain (25分)

1 题目 1106 Lowest 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...

韩江雪de 小屋 678

PAT 甲级 1106  Lowest Price in Supply Chain

1106 Lowest 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....

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

1106 Lowest Price in Supply Chain

题目 改写自:原题 题意: 提供一棵树,在树根处货物的价格为p,从根结点开始每往下一层,该层货物价格将会在父亲结点的价格上增加r%。求叶子结点出能获得的最低价格以及能提供最低价格的叶子结点数tip:路径压缩 #include<iostream> #include<algorithm> #include<cmath> using namespace std...

qq_1300258993的博客 355

PAT 1106 Lowest Price in Supply Chain (25分)

原题链接:1106 Lowest Price in Supply Chain (25分) 关键词:DFS、树的遍历 题目大意: 给出你供销链中的成员,原始价格和每经过一人多上涨的利率,问你最后到达零售商的最便宜的价格以及给出最便宜的价格的零售商数。

cwtnice的博客 207

1106 Lowest Price in Supply Chain (25 分)

1106Lowest 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. Start...

chen_zan_yu_的博客 164

甲级1106 Lowest Price in Supply Chain (25 分)

1106 Lowest 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. Startin...

weixin_44751612的博客 205

1106 Lowest Price in Supply Chain (25 分)

Keyword: 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, e...

qq_39339575的博客 215
上一篇: 1099 Build A Binary Search Tree (30 point(s))
下一篇: 1097 Deduplication on a Linked List (25 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值