[建树(非二叉树)] 1106. Lowest Price in Supply Chain (25)
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)的更多相关文章
- [建树(非二叉树)] 1090. Highest Price in Supply Chain (25)
1090. Highest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors ...
- 1106. Lowest Price in Supply Chain (25)
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- PAT Advanced 1106 Lowest Price in Supply Chain (25) [DFS,BFS,树的遍历]
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...
- PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)
简单dfs #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT甲题题解-1106. Lowest Price in Supply Chain (25)-(dfs计算树的最小层数)
统计树的最小层数以及位于该层数上的叶子节点个数即可. 代码里建树我用了邻接链表的存储方式——链式前向星,不了解的可以参考,非常好用: http://www.cnblogs.com/chenxiwenr ...
- 【PAT甲级】1106 Lowest Price in Supply Chain (25分)
题意:输入一个正整数N(<=1e5),两个小数P和R,分别表示树的结点个数和商品原价以及每下探一层会涨幅的百分比.输出叶子结点深度最小的商品价格和深度最小的叶子结点个数. trick: 测试点1 ...
- PAT甲级——1106 Lowest Price in Supply Chain(BFS)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90444872 1106 Lowest Price in Supp ...
- PAT 甲级 1106 Lowest Price in Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805362341822464 A supply chain is a ne ...
- PAT 1106 Lowest Price in Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
随机推荐
- telerik WinForm主题切换
通过按钮或Form_Load中切换: ThemeResolutionService.ApplicationThemeName = "Windows 7"; //具体的主题名,不同的 ...
- 20145226 2016-2017-2 夏艺华 《Java程序设计》 课程总结
20145226夏艺华 <Java程序设计>课程总结 每周读书笔记链接汇总 第一周读书笔记 了解Java编程风格,认识Java的类型与变量,掌握Java流程控制的方法(分支.循环). ht ...
- 数据增强利器--Augmentor
最近遇到数据样本数目不足的问题,自己写的增强工具生成数目还是不够,终于在网上找到一个数据增强工具包,足够高级,足够傻瓜.想要多少就有多少!再也不怕数据不够了! 简介 Augmentor是一个Pytho ...
- 几种交叉验证(cross validation)方式的比较
模型评价的目的:通过模型评价,我们知道当前训练模型的好坏,泛化能力如何?从而知道是否可以应用在解决问题上,如果不行,那又是哪里出了问题? train_test_split 在分类问题中,我们通常通过对 ...
- 洛谷 P1939 【模板】矩阵加速(数列)
题目描述 a[1]=a[2]=a[3]=1 a[x]=a[x-3]+a[x-1] (x>3) 求a数列的第n项对1000000007(10^9+7)取余的值. 输入输出格式 输入格式: 第一行一 ...
- 13 - stark总结、github代码
1.stark - 总结 (单例,继承,反射,面向对象,modelform 应用得很好!!) 1.注册表 单例模式 site = StarkSite() 2.生成url url(r'^stark/', ...
- [SDOI2018]战略游戏 圆方树,树链剖分
[SDOI2018]战略游戏 这题是道路相遇(题解)的升级版,询问的两个点变成了\(S\)个点. LG传送门 还是先建出圆方树,考虑对于询问的\(S\)个点,答案就是圆方树上能包含这些点的最小连通块中 ...
- [算法总结] 20 道题搞定 BAT 面试——二叉树
本文首发于我的个人博客:尾尾部落 0. 几个概念 完全二叉树:若二叉树的高度是h,除第h层之外,其他(1~h-1)层的节点数都达到了最大个数,并且第h层的节点都连续的集中在最左边.想到点什么没?实际上 ...
- skipfish介绍
skipfish 开发语言:C语言 命令行扫描器 主动扫描web安全评估工具 谷歌开发 已经不再进行维护 重点关注web代码 通过两种方式进项扫描:1.字典枚举 2.递归爬网 优点:速度快.支持多路单 ...
- 04-matplotlib-柱形图
import numpy as np import matplotlib.pyplot as plt # 柱形图 # 例一 N =5 y = [15,28,10,30,25] index = np.a ...