https://pintia.cn/problem-sets/994805342720868352/problems/994805362341822464

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 (≤), 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 Nlines 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 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

代码:

#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
int N;
double P, r;
vector<int> v[maxn];
int vis[maxn];
int cnt = INT_MAX;
int ans = 0; void dfs(int st, int depth) {
if(v[st].size() == 0) {
if(depth < cnt) {
cnt = depth;
ans = 1;
} else if(depth == cnt) ans ++;
} for(int i = 0; i < v[st].size(); i ++)
dfs(v[st][i], depth + 1); } int main() {
scanf("%d%lf%lf", &N, &P, &r);
memset(vis, 0, sizeof(vis));
for(int i = 0; i < N; i ++) {
int k;
scanf("%d", &k);
while(k --) {
int x;
scanf("%d", &x);
v[i].push_back(x);
}
} dfs(0, 0);
r /= (1.0 * 100);
double sum = 1.0;
for(int i = 0; i < cnt; i ++)
sum *= (r + 1);
sum = sum * P;
printf("%.4lf %d\n", sum, ans);
return 0;
}

  dfs 

PAT 甲级 1106 Lowest Price in Supply Chain的更多相关文章

  1. PAT甲级——1106 Lowest Price in Supply Chain(BFS)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90444872 1106 Lowest Price in Supp ...

  2. PAT甲级——A1106 Lowest Price in Supply Chain

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  3. PAT Advanced 1106 Lowest Price in Supply Chain (25) [DFS,BFS,树的遍历]

    题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...

  4. [建树(非二叉树)] 1106. Lowest Price in Supply Chain (25)

    1106. Lowest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors( ...

  5. PAT 1106 Lowest Price in Supply Chain

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  6. 1106. Lowest Price in Supply Chain (25)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  7. PAT 甲级 1090 Highest Price in Supply Chain

    https://pintia.cn/problem-sets/994805342720868352/problems/994805376476626944 A supply chain is a ne ...

  8. PAT甲级——A1090 Highest Price in Supply Chain

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  9. 【PAT甲级】1106 Lowest Price in Supply Chain (25分)

    题意:输入一个正整数N(<=1e5),两个小数P和R,分别表示树的结点个数和商品原价以及每下探一层会涨幅的百分比.输出叶子结点深度最小的商品价格和深度最小的叶子结点个数. trick: 测试点1 ...

随机推荐

  1. std::lexicographical_compare函数的使用

    按照词典序比较前者是否小于后者. 当序列<first1, last1>按照字典序比较小于后者序列<first2, last2>,则返回true.否则,返回false. 所谓字典 ...

  2. Dubbo -- 系统学习 笔记 -- 目录

    用户指南 入门 背景 需求 架构 用法 快速启动 服务提供者 服务消费者 依赖 必需依赖 缺省依赖 可选依赖 成熟度 功能成熟度 策略成熟度 配置 Xml配置 属性配置 注解配置 API配置 示例 启 ...

  3. django表格form无法保存评论排查步骤

    初学django项目,在网上找了个blog教程,还是很不错的,这里感谢一下博主https://www.zmrenwu.com/post/2/ 这个项目适合django初学者,是一个完整的blog项目 ...

  4. [转]学习C#:Attribute与Property

    一.什么是Attribute 先看下面的三段代码: 1.自定义Attribute类:VersionAttribute [AttributeUsage(AttributeTargets.Class)] ...

  5. OpenCV——膨胀与腐蚀

  6. .NET批量操作窗口样式

    1. 背景 我们在开发过程中,可能会遇到需要批量控制程序中窗体的大小或其它一些操作, 这些窗体有可能是属于程序本身的,也许是其它程序的窗口.本文就是基于此的一篇关于如何批量操作窗口样式的,我们主要是通 ...

  7. CentOS7服务器配置网络

    Centos7最小化安装 [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-enp5s0f0编辑如下:TYPE=Ethernet ...

  8. jsonp小案例

    jsonp详解 例子:

  9. day60

    Bootstrap 一.简介 Bootstrap是美国Twitter公司的设计师Mark Otto和Jacob Thornton合作基于HTML.CSS.JavaScript 开发的简洁.直观.强悍的 ...

  10. ORA-02291: 违反完整约束条件 - 未找到父项关键字

    由于大意,在设置数据库表时将外键字段的类型与外键表的主键字段类型不一致,造成此错误. 我的情况是: 1.将一个为number(10)的外键设置成了number(19) 2.将外键字段对应的主键表设置成 ...