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. QuestaSim 中文注释乱码

    在QuestaSim按如下顺序打开对应窗口, Tools -> Edit Preferences -> By Name -> Find 输入 encoding搜索对应项,将其valu ...

  2. RMAN 与control文件和spfile文件的备份

    以10.2为例,官方文档如此说: http://docs.oracle.com/cd/B19306_01/backup.102/b14191/rcmconc1.htm The RMAN behavio ...

  3. v$pwfile_user表

    SQL> select * from v$pwfile_users;select * from v$pwfile_users; USERNAME SYSDB SYSOP SYSAS------- ...

  4. 【转】numpy教程

    [转载说明] 本来没有必要转载的,只是网上的版本排版不是太好,看的不舒服.所以转过来,重新排版,便于自己查看. 基础篇 NumPy的主要对象是同种元素的多维数组. 这是一个所有的元素都是一种类型.通过 ...

  5. 【转载】MSXML应用总结 开发篇(上)

    原文:http://blog.sina.com.cn/s/blog_48f93b530100ejv9.html 本篇是接前文“MSXML应用总结 概念篇”写的,主要总结一下MSXML DOM接口的应用 ...

  6. 4008: [HNOI2015]亚瑟王

    4008: [HNOI2015]亚瑟王 链接 分析: 根据期望的线性性,直接求出每张牌出现的概率,最后乘以攻击力就是答案. 每张牌出现的概率只与它前面的牌有关,与后面的没有关系,于是按顺序考虑每张牌. ...

  7. 联赛emacs配置

    (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you co ...

  8. 团队合作开发git冲突解决方案 Intellij IDEA

    https://blog.csdn.net/antony9118/article/details/52524873 注:因为我使用的是 idea 2018.1.2的版本,所以在操作上有些变化 将某些操 ...

  9. python之shutil模块详解

    shutil模块 -- --High-level file operations  高级的文件操作模块. os模块提供了对目录或者文件的新建/删除/查看文件属性,还提供了对文件以及目录的路径操作.比如 ...

  10. 基于Cocos2d-x-1.0.1的飞机大战游戏迁移到Cocos2d-x-3.0版本,并移植到Android平台成功运行

    一.版本迁移中的问题 1.游戏元素Sprite.Label.Action等等的创建函数名都改为create. 2.函数的回调callfunc_selectorcallfuncN_selectorcal ...