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<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int ans[][]; bool cmp(int a,int b)
{
return a > b;
} struct node
{
vector<int> child;
}; node Tree[]; int MIN = ;
int cnt = ;
void DFS(int root,int level)
{
if(Tree[root].child.empty())
{
if( level < MIN)
{
MIN = level;
cnt = ;
}
else if (level == MIN)
++cnt;
}
else
{
for(int i = ; i < Tree[root].child.size();++i)
DFS(Tree[root].child[i],level+);
}
} int main()
{
int n,num,tem;
double pri,rate;
scanf("%d%lf%lf",&n,&pri,&rate);
vector<int> vv;
for(int i = ;i < n ;++i)
{
scanf("%d",&num);
for(int k = ;k <num ;++k)
{
scanf("%d",&tem);
Tree[i].child.push_back(tem);
}
} DFS(,); printf("%.4lf %d\n",pri * pow((100.0+rate)/100.0,MIN),cnt); return ;
}
1106. Lowest Price in Supply Chain (25)的更多相关文章
- [建树(非二叉树)] 1106. Lowest Price in Supply Chain (25)
1106. Lowest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors( ...
- 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 ...
- 1106 Lowest Price in Supply Chain (25 分)(树的遍历)
求叶子结点处能活得最低价格以及能提供最低价格的叶子结点的个数 #include<bits/stdc++.h> using namespace std; ; vector<int> ...
随机推荐
- 推荐一款好用的项目管理工具:project
Microsoft Project (MSP)是微软开发的一个国际上享有盛誉的通用的项目管理工具软件. 在项目管理的时候,这个软件可以帮你定制时间计划,还有其它很多好用的功能. 2010版本的下载传送 ...
- PHP trim()函数的一些用法
string trim ( string $str [, string $charlist ] ) - 去除字符串首尾处的空白字符(或者其他字符) trim()函数当第二个参数为空时,默认去掉空格.制 ...
- Linux常用命令之seq
标题:seq命令的使用 作用:seq命令用于以指定增量从首数开始打印数字到尾数,即产生从某个数到另外一个数之间的所有整数,并且可以对整数的格式.宽度.分割符号进行控制 语法: [1] seq [选项] ...
- springmvc(3)--数据类型转换
springmvc 配置 中conversionService可以配置类型转换,springmvc 参数绑定 中各种绑定方式和注解就是使用的这些转换器 一.先看下spring提供的内建类型转换器 第一 ...
- 【转】ConcurrentHashMap完全解析(JDK6/7、JDK8)
转自http://my.oschina.net/hosee/blog/675884 并发编程实践中,ConcurrentHashMap是一个经常被使用的数据结构,相比于Hashtable以及Colle ...
- 剑指Offer11 在O(1)内删除链表结点
/************************************************************************* > File Name: 11_Delete ...
- LeetCode 337
House Robber III The thief has found himself a new place for his thievery again. There is only one e ...
- HTML页面中常见的一些小方法
在<Head>标签中加 <meta http-equiv="pragma " content="no-cache"> <met ...
- Android聊天界面刷新消息
今天,我想来分享一下自己初用线程的感受,虽然写法略显粗糙,并没有用线程Thread中核心的Looper,MessageQueue消息队列这些知识,正因为是初学线程,所以就只用最基础的来写了,慢慢学习优 ...
- ORACLE 数据库概述以及Oracel数据库的安装、卸载、使用
一:Orcale简介 1.发展史 1978年,Orcale诞生 1982年,Orcale3推出了,它是第一个能够运行在大型机和小型机上的关系型数据库 1997年,Orcale公司推出了基于java语言 ...