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.

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 (<=105), 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:

Ki ID[1] ID[2] ... ID[Ki]

where in the i-th line, Ki 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. Kj 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 1010.

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 <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int INF=1e9;
const int maxn=; struct Node
{
int data;
vector<int> child;
}node[maxn];
int min_deep=INF;
int num[maxn]={}; void dfs(int s,int & deep)
{
if(node[s].child.size()==)
{
num[deep]+=;
if(deep<min_deep)
{
min_deep=deep;
}
return ;
}
for(int i=;i<node[s].child.size();i++)
{
int v=node[s].child[i];
deep++;
dfs(v,deep);
deep--;
}
} int main()
{
int n;
double p,r;
cin>>n>>p>>r;
for(int i=;i<n;i++)
{
int k;
cin>>k;
int id;
for(int j=;j<k;j++)
{
cin>>id;
node[i].child.push_back(id);
}
}
int deep=;
dfs(,deep);
deep=min_deep;
double sum=p;
while(min_deep>)
{
min_deep-=;
sum*=1.0+r/;
}
//printf("debug:%d",min_deep);
printf("%.4lf %d\n",sum,num[deep]);
}

[建树(非二叉树)] 1106. Lowest Price in Supply Chain (25)的更多相关文章

  1. [建树(非二叉树)] 1090. Highest Price in Supply Chain (25)

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

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

    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. PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)

    简单dfs #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

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

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

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

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

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

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

  8. PAT 甲级 1106 Lowest Price in Supply Chain

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

  9. PAT 1106 Lowest Price in Supply Chain

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

随机推荐

  1. 小米路由器设置端口转发远程登录WEB管理页及安装MT工具箱

    1. 将小米路由器ROM升级到开发版 这一点是必须的,如果是稳定版是不行的 2. 获取高级管理权限 再次确认当前使用的是开发版ROM 到这个网址http://d.miwifi.com/rom/ssh ...

  2. golang实现简单的栈

    栈的ADT 数据 栈的数据对象集合为{a1,a2,a3...an},具有相同数据类型,有唯一前驱后续 操作 InitStack() *Stack //初始化操作,创建一个空栈 Clear() //清空 ...

  3. Properties读取小结

    一.Java程序中读取properties文件 加载的工具类: import java.io.File; import java.io.FileOutputStream; import java.io ...

  4. python+soket实现UDP协议的客户/服务端中文聊天程序

    没什么特别的东西,网上烂大街的C/S框架.(基于windows 7 + python 3.4) 为了实现中文聊天,我加入了一点修改: msg.encode('utf-8') # msg 为输入(且将要 ...

  5. [CQOI2012]组装 贪心

    [CQOI2012]组装 贪心好题. LG传送门 首先有一个必须要能推的式子:设第\(i\)种零件选的生产车间位置为\(x _ i\),组装车间位置为\(x\), 则总的花费为 \[f(x) = \s ...

  6. PHP Rabbitmq 报错Broken pipe

    fwrite(): send of 13 bytes failed with errno=32 Broken pipe fwrite(): send of 21 bytes failed with e ...

  7. linux安装anaconda3

    1,查看系统的版本  Uname –r 2,安装git 等依赖库 yum install git yum install zlib-devel bzip2-devel openssl-devel nc ...

  8. 人工智能AI芯片与Maker创意接轨 (中)

    在人工智能AI芯片与Maker创意接轨(上)这篇文章中,介绍人工智能与深度学习,以及深度学习技术的应用,了解内部真实的作业原理,让我们能够跟上这波AI新浪潮.系列文来到了中篇,将详细介绍目前市面上的各 ...

  9. [Unity3D]MonoDeveloper快捷键(补全代码补全引用中文乱码tab转空格)

    Hello亲爱的观众朋友们大家好,我是09. vs支持各种插件,一般推荐用vs.不过总有人(例如我)由于各种原因用MonoDeveloper.苦于每次上网找各种设置,此处集中写下我用MonoDevel ...

  10. Robot的使用

    在Java中,有一个类,非常神奇,它能帮助你完成某些任务,例如:打开笔记本/QQ等. 今天,我就说一下Robot类的使用方法吧,做一个打开记事本的小程序. 1.准备工作 JDK:不知道的别看了 开发工 ...