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> ...
随机推荐
- 【Android 界面效果18】Android软件开发之常用系统控件界面整理
[java] view plaincopyprint? <span style="font-size:18px">1.文本框TextView TextView的作用 ...
- 【Mood-3】心声
每天醒来,我都会想明白一件事情,时间是不会停下来的,如果打算活下去的话,那么我们会有25岁,会有30岁,更会有40岁,为了不让时间风干我的理想,未来只剩下抱怨,那么为明天伏笔,今天只有努力.耸耸背上行 ...
- 一个Java线程死锁的例子
package com.lk.B; public class Test4 { private static final Object o1 = new Object(); private static ...
- CF Sea and Islands
Sea and Islands time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- 抽奖随机算法的技术探讨与C#实现
一.模拟客户需求 1.1 客户A需求:要求每次都按照下图的概率随机,数量不限,每个用户只能抽一次,抽奖结果的分布与抽奖概率近似. 1.2 客户B需求:固定奖项10个,抽奖次数不限,每个用户只能抽一次, ...
- NodeJS学习之网络操作
NodeJS -- 网络操作 使用NodeJS内置的http模块简单实现HTTP服务器 var http = require('http'); http.createServer(function(r ...
- Javascript中关于数组的认识
昨天在练习js中cookie的时候,知道js中的cookie是一个字符串,这与php中的操作cookie还是有很大的差别的,起初我是以php的思维来学习怎么样使用使用js中的cookie. js中的c ...
- springMVC第一课--配置文件
刚学springMVC,记录下学习过程,供以后查阅(githup源码). 1,新建一个web工程.(其他按常规来) 如下:添加applicationContext.xml,webmvc-servlet ...
- WinFrom“动态”WebService
1.首先添加一个WebService: 2.输入地址....Ok: 3.在WebService用到的类上按F12: 4.进入类中,找到其构造函数: 5.修改其构造函数为代参数,并且让this.Url= ...
- Jquery 格式化时间
我们常常会通过datetime得到时间,但是网页前台往往会显示不同的时间 如:2013-12-15 2013年12月23日 2013 12 15 等多种显示效果,这就需要我们把时间格式化一下. 下面是 ...