Source:

PAT A1106 Lowest Price in Supply Chain (25 分)

Description:

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 Pand 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 (≤), 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:

K​i​​ ID[1] ID[2] ... ID[K​i​​]

where in the i-th line, K​i​​ 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. K​j​​ 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 1.

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

Keys:

Attention:

  • 加上剪枝的话,层次遍历会更快一些,深度遍历比较好写-,-

Code:

 /*
time: 2019-06-28 14:08:25
problem: PAT_A1106#Lowest Price in Supply Chain
AC: 24:26 题目大意:
供应链网络:供应商->经销商->零售商->消费者
只有一个供应商,经销商以价格P从供应商进货,再以溢价r%出售给下一级经销商,最终至零售商出售给消费者
求出消费者购买商品的最低价格
输入:
第一行给出,结点数N<=1e5(编号0~n-1,root为0),出厂价P,溢价百分率r
接下来N行,结点i的孩子结点数量,各孩子结点编号
输出:
最低价格(4位小数),零售商数量(叶子结点数量) 基本思路:
实质就是遍历一个树,求叶子结点中最浅的层次和个数
*/
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
const int M=1e5+;
vector<int> chain[M];
int cnt=,minDeep=M;
double r,p; void Travel(int root, int hight)
{
if(minDeep < hight)
return;
if(chain[root].size() == )
{
if(hight < minDeep)
{
minDeep = hight;
cnt = ;
}
else if(minDeep == hight)
cnt++;
return;
}
for(int i=; i<chain[root].size(); i++)
Travel(chain[root][i], hight+);
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,k,v;
scanf("%d%lf%lf", &n,&p,&r);
for(int i=; i<n; i++)
{
scanf("%d", &k);
for(int j=; j<k; j++)
{
scanf("%d", &v);
chain[i].push_back(v);
}
}
Travel(,);
printf("%.4f %d", p*pow((1.0+r/),minDeep), cnt); return ;
}

PAT_A1106#Lowest Price in Supply Chain的更多相关文章

  1. PAT1106:Lowest Price in Supply Chain

    1106. Lowest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CH ...

  2. [建树(非二叉树)] 1106. Lowest Price in Supply Chain (25)

    1106. Lowest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors( ...

  3. PAT甲级——1106 Lowest Price in Supply Chain(BFS)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90444872 1106 Lowest Price in Supp ...

  4. 1106. Lowest Price in Supply Chain (25)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  5. A1106. Lowest Price in Supply Chain

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  6. PAT A1106 Lowest Price in Supply Chain (25 分)——树的bfs遍历

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  7. PAT 甲级 1106 Lowest Price in Supply Chain

    https://pintia.cn/problem-sets/994805342720868352/problems/994805362341822464 A supply chain is a ne ...

  8. PAT 1106 Lowest Price in Supply Chain

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  9. PAT甲级——A1106 Lowest Price in Supply Chain

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

随机推荐

  1. Android项目中引用到其他工程

    有的时候我们需要在现有的项目中引用到其他项目的资源和文件,当然我们可以将被引用的工程打成jar包,但是这有个缺点就是,这个改动比较麻烦,除非是被引用的工程的资源和源程序文件不再改动,可以这样做,否则每 ...

  2. 数学思维——cf351A

    把每个值的各种贡献算一下即可 /* ai的小数部分为xi,向下取整对答案贡献为xi 向上取整对答案的贡献是xi-1,如果这个数是0,那么对答案的贡献是xi,即如果0向上取整就可以免去-1 然后sum{ ...

  3. 在delphi中执行javascript代码

    有时做项目难免用到代码交叉调用,delphi中执行js就是一种,两种方法可用: 一.使用webbrower,比较麻烦 二.使用ScriptControl,简单方便: 1.首先 uses ComObj; ...

  4. Ext 选项卡面板TabPanel

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. readUTF()和writeUTF()

    readUTF()和writeUTF() 这是dataOutputStream 的方法~~使用utf-8编码 其实就是从unicode变过来的,utf8编码把unicode的ASCII编码变成1个字节 ...

  6. Linux 线程Demo

    #include <stdio.h> #include <pthread.h> struct char_print_params { char character; int c ...

  7. 通过MyEclipse操作数据库,执行sql语句使我们不用切换多个工具,直接工作,方便快捷

    通过MyEclipse操作数据库,执行sql语句使我们不用切换多个工具,直接工作,方便快捷.效果如下:     步骤1:通过MyEclipse中的window->show View->ot ...

  8. swiper实现上下滑动翻页,内置内容页也滚动

    如果我猜的没错,是全网(哈哈)比较少的成功解决方案,如需要转载,请声明并转载出处. swiper实现了上下滑动翻页,但是有几个页面的内容显示不完.如果一页显示不完时可以滑动查看,应该怎么做?这个是我多 ...

  9. HBase1.0.0 实现数据增删查

    HBase1.0.0 即Hadoop 2.6 采用maven 的方式实现HBase数据简单操作 import java.io.IOException; import java.util.ArrayLi ...

  10. 为Python终端提供持久性历史记录

    有没有办法告诉交互式Python shell在会话之间保留其执行命令的历史记录? 当会话正在运行时,在执行命令之后,我可以向上箭头并访问所述命令,我只是想知道是否有某种方法可以保存这些命令,直到下次我 ...