[建树(非二叉树)] 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 ...
随机推荐
- SEO优化上首页之搜索引擎用户需求理解
经过前面<搜索引擎原理SEO优化上首页之网络蜘蛛Spider>和<搜索引擎原理SEO优化上首页之内容处理与创建索引>介绍,搜索引擎已经完成页面抓取和分析,并把原始页面.索引等信 ...
- updated stream stash changes
处理的方式非常简单,主要是使用git stash命令进行处理,分成以下几个步骤进行处理. 1.先将本地修改存储起来 $ git stash 这样本地的所有修改就都被暂时存储起来 .是用git stas ...
- 【HNOI2014】米特运输
题面 题解 首先我们需要看懂题目 然后我们需要发现一个结论 只要有一个节点的权值确定,那么整棵树的权值就确定了 就像这样:(图片来源于网络,侵删) 然后我们根据这张图片,可以设\(f[i] = a[i ...
- 洛谷NOIp热身赛题解
洛谷NOIp热身赛题解 A 最大差值 简单树状数组,维护区间和.区间平方和,方差按照给的公式算就行了 #include<bits/stdc++.h> #define il inline # ...
- Kali2.0可用国内源更新sources.list
vim /etc/apt/sources.list #中科大 deb http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contri ...
- 轻量级企业私有云 JimV 分享
当前云市场分析 云分两种,公有云.私有云.目前市面上的云产品,对于中小规模的企业来讲,痛点有如下几点: 私有云: 1.VMware ESXi 类: a) 授权费用昂贵: b) 创建虚拟机费时费力: 2 ...
- c# ajax从后台获取数据list数组 $.each再显示数据
后台代码 public JsonResult linkage(string Department) {//逻辑是:先从数据库查到表数据 再把表数据转换为LIST给AJAX HE_Department ...
- JavaScript 数组——filter()、map()、some()、every()、forEach()、lastIndexOf()、indexOf()
filter(): 语法: var filteredArray = array.filter(callback[, thisObject]); 参数说明: callback: 要对每个数组元素执行 ...
- python-我的第一门编程语言
一.认识python是一个偶然,由于大学不务正业,混迹于各种电脑维修群(本人专业商务经济专业),了解过C.JAVA.HTML5以及世界上最好的编程语言PHP and so on!了解也仅仅是了解. 二 ...
- 在WebGL场景中管理多个卡牌对象的实验
这篇文章讨论如何在基于Babylon.js的WebGL场景中,实现多个简单卡牌类对象的显示.选择.分组.排序,同时建立一套实用的3D场景代码框架.由于作者美工能力有限,所以示例场景视觉效果可能欠佳,本 ...