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. sql优化常见的集中方法

    在sql查询中为了提高查询效率,我们常常会采取一些措施对查询语句进行sql优化,下面总结的一些方法,有需要的可以参考参考. 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 ord ...

  2. Ant在MyEclipse中的配置总结

    1.在配置Ant之前,先要配置好JDK的JAVA_HOME和path:之后下载解压apache-ant-1.7.1;并配置环境变量ANT_HOME(安装目录,后不可以加分号:)及其path(安装目录/ ...

  3. WorldWind源码剖析系列:大气层散射球类AtmosphericScatteringSphere

    大气层散射球类AtmosphericScatteringSphere代表地球外面的大气层散射球模型,可以控制开启/关闭渲染该对象.该类的类图如下. 该类所包含的主要字段.属性和方法如下: public ...

  4. day63

    一.环境搭建 1.安装node 去官网下载node安装包 傻瓜式安装 万一安装后终端没有node环境,要进行node环境变量的配置(C:\Program Files\nodejs) 可以通过node提 ...

  5. 微信小程序开发 [02] 页面注册和基本组件

    1.页面注册 既然我们希望跳转到新的页面,那自然要新建页面相关的文件才行.在开篇已经讲过,一个小程序页面由四个文件组成,假如我们的页面名为welcome,那么这四个文件则是: welcome.js w ...

  6. struts2_文件上传的功能

    使用Struts内置的fileUpload拦截器(已默认配置)即可,设计的电商网站,提供用户头像上传的功能 1. 2. 3. 4. 5. 5.未使用拦截器 6.未使用filename 7. 8. 9.

  7. 20155207 EXP7 EXP8 EXP9 实验补交

    20155207 EXP7 EXP8 EXP9 实验补交 20155207 EXP7 网络欺诈技术防范 20155207 EXP8 Web基础 20155207 <网络对抗> Exp9 W ...

  8. 20155305乔磊《网络对抗》逆向及Bof基础

    20155305乔磊<网络对抗>逆向及Bof基础 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何 ...

  9. Javascript 地图库收集

    ArcGis leafletjs openlayers jvectormap

  10. pandas 索引与列相互转化

    1. 准备数据 import pandas as pd from io import StringIO csv_txt = '''"date","player1" ...