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
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int maxn = 100010;
const double INF = 1e12;
vector<int> Child[maxn];
double p,r,ans = INF;
int n,num = 0;void DFS(int index,int depth){   if(Child[index].size() == 0){double price = p * pow(1+r,depth);if(price < ans){   //最低价格要和最高价格算法区别开 ans = price;  //前者直接求出叶节点处价格的大小进行比较 num = 1;       //后者可以直接比较叶节点处的深度 }else if(price == ans){num++;}return;}for(int i = 0; i < Child[index].size(); i++){DFS(Child[index][i],depth+1);}
}int main(){scanf("%d%lf%lf",&n,&p,&r);r /= 100;int child,k;for(int i = 0; i < n; i++){scanf("%d",&k);if( k != 0){for(int j = 0; j < k; j++){scanf("%d",&child);Child[i].push_back(child);}}}DFS(0,0);printf("%.4lf %d",ans,num);return 0;
}

Sample Output:

1.8362 2

转载于:https://www.cnblogs.com/wanghao-boke/p/9294036.html

1106 Lowest Price in Supply Chain (25)相关推荐

  1. PAT甲级 -- 1106 Lowest Price in Supply Chain (25 分)

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

  2. 1106. Lowest Price in Supply Chain (25)-PAT甲级真题(dfs,bfs,树的遍历)

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

  3. PAT甲题题解-1106. Lowest Price in Supply Chain (25)-(dfs计算树的最小层数)

    统计树的最小层数以及位于该层数上的叶子节点个数即可. 代码里建树我用了邻接链表的存储方式--链式前向星,不了解的可以参考,非常好用: http://www.cnblogs.com/chenxiwenr ...

  4. 1106 Lowest Price in Supply Chain(甲级)

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

  5. PAT甲级1106 Lowest Price in Supply Chain:[C++题解]树、结点到根结点的距离、树形dp、记忆化搜索

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析:这道题是第三次做了. 和PAT甲级1079 Total Sales of Supply Chain:[C++题解] 树.结点到根结点的 ...

  6. 1106 Lowest Price in Supply Chain

    1. 本题和1090 Highest Price in Supply Chain适成对比,都是先构建一棵树,但本题是求最小层数和个数,链接题是求最大层数和个数.在极值更换和个数更新方面,两道题是一样的 ...

  7. PAT_A1106#Lowest Price in Supply Chain

    Source: PAT A1106 Lowest Price in Supply Chain (25 分) Description: A supply chain is a network of re ...

  8. 【PAT】A1106 Lowest Price in Supply Chain

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

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

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

最新文章

  1. Asp.net Mvc问题索引
  2. python安装requests库超时_【Python 库】requests 详解超时和重试
  3. BUUCTF Web [GXYCTF2019]Ping Ping Ping
  4. SQLite 的日期时间函数
  5. 解决Python开发中,Pycharm中无法使用中文输入法问题
  6. Hadoop切换namenode为active
  7. 云服务器真假辨别奥秘
  8. OllyDBG 入门
  9. 小程序apkg还原_谈一谈还原解包后小程序页面wxss样式的若干方法
  10. [连载2]互联网究竟是什么怪物…他们不愿公开真正秘密...
  11. php文字转拼音API接口下载,微擎API 开发之汉字转拼音助手
  12. 的it生活_双子IT男性格随和、爱美食懂生活,会给女朋友准备小惊喜 | 企鹅来电VOL.03...
  13. 一款软件界面的重要性
  14. C语言——三目运算符的进阶用法,比较三个或者四个数的大小
  15. Maven 项目自动构建 Docker 镜像推送到 Docker 服务器
  16. Variant 数据类型介绍
  17. 华为公有云认证培训认证体系- HCIA,HCIP ,HCIE
  18. 如何用PS批量裁剪照片
  19. 电商行业防御黑客攻击解决方案
  20. 使用AlarmManager设置闹钟

热门文章

  1. nsis 修改exe执行权限
  2. js技巧收集(200多个)
  3. C语言学习,关于fflush 和setvbuf
  4. c mysql二进制,MySQL运用connector C/C+读取二进制字段
  5. springboot2 使用hikaridatasource 并测试_基于Spring Boot 2.x的后端管理网站脚手,源码免费分享...
  6. 阿里云centos 7.6安装mysql_阿里云Centos7上安装MySQL教程
  7. 数组中第K个最大元素
  8. java打印菱形代码_Java打印菱形高效简洁代码
  9. 【智能车Code review】——坡道图像与控制处理
  10. sql的外键约束和主键约束_SQL约束