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. java 计算百分数方法

    俗话说好记性不如烂笔头,故记之. DecimalFormat decimalFormat = new DecimalFormat("##.00%"); System.out.pri ...

  2. Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP

    <?php class Car { var $color = "add"; function Car($color="green") { $this-&g ...

  3. rebase合并commit步骤详解

    网上关于rebase合并commit有很多文章,但大部分中间一些步骤没有写明 第一步:在终端输入 git rebase -i [startPoint] [endPoint] 并回车 第二步:编辑指令, ...

  4. Locust环境搭建及应用-hc课堂笔记

    Locust环境搭建: 1,在命令窗口中,进入到python项目路径,如:d:\Pycharmproject\venv\Scripts 2,执行Scripts下的active.bat,进入到虚拟环境 ...

  5. JS输入框邮箱自动提示(带有demo和源码)

    今天在javascriptQQ群里面 有童鞋问到 有没有 "JS输入框邮箱自动提示"插件,即说都找遍了github上源码 都没有看到这样类似的插件,然后我想了下 "JS输 ...

  6. $\rm{NOIP}$前的模拟题整理·菜鸡互啄篇

    嗯,打算整理一下我们机房菜鸡互啄中比较不错的题-- 大概情况就是每个人出三道题,然后互测这种感觉-- 至于某些Y姓基佬.Z姓基佬偷偷出原题--就不说了233 嗯,剩下的就先\(magpie\)着吧23 ...

  7. Arduino入门笔记(3):单LED闪烁

    转载请注明:@小五义http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 在搭建好arduino开发环境(http://www.cnblogs.com/xi ...

  8. Android 给CheckBox设置背景

    一般来说我们给控件(Button,LinearLayout,ImageView,TextView等)设这背景的时候只需要设置这些控件的android:background即可, 但是在给CheckBo ...

  9. cloudstack的虚拟机arp -a时网关的mac地址 都是Incomplete

    定位ARP攻击源头和防御方法 主动定位方式:因为所有的ARP攻击源都会有其特征——网卡会处于混杂模式,可以通过ARPKiller这样的工具扫描网内有哪台机器的网卡是处于混杂模式的,从而判断这台机器有可 ...

  10. Python3入门(十)——调试与测试

    一.异常处理 1.try...except...finally... 这个也就是Java里的try...cath..finally...了,直接看经典代码: try: print("开始执行 ...