1106 Lowest Price in Supply Chain

大致题意就是给出一棵树,求出叶子结点的最小权值,并输出该叶子节点的个数。

这是一道模板题,我近期做的几乎都是模板题。我现在认为 树与二叉树 是对 图 的一种严格约束,并且“二叉树,树,图”使用邻接表的存储结构比较多。

 1 #include<iostream>
 2 #include<vector>
 3 #include<map>
 4 using namespace std;
 5
 6 const int maxn = 100010;
 7 vector<int> node[maxn];
 8 int n,k,child;
 9 double p,r;
10 map<double,int> mp;
11 void DFS(int root, double price) { //树的先序遍历
12     if(node[root].size() == 0) { //叶子节点
13         mp[price]++;
14         return ;
15     }
16     for(int i = 0; i < node[root].size(); ++i) {
17         DFS(node[root][i],price*(1+r));
18     }
19 }
20
21 int main() {
22     cin>>n>>p>>r;
23     r/=100;
24     for(int i = 0; i < n; ++i) {
25         cin>>k;
26         if(k != 0) {
27             for(int j = 0 ; j < k; ++j) {
28                 cin>>child;
29                 node[i].push_back(child);
30             }
31         }
32     }
33     DFS(0,p);
34     auto it = mp.begin();
35     printf("%.4f %d",it->first,it->second);
36     return 0;
37 }

原文地址:https://www.cnblogs.com/keep23456/p/12400583.html

时间: 2024-10-06 05:12:51

1106 Lowest Price in Supply Chain的相关文章

[建树(非二叉树)] 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 buy

1106. Lowest Price in Supply Chain (25)【树+深搜】——PAT (Advanced Level) Practise

题目信息 1106. Lowest Price in Supply Chain (25) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone involved in moving a product from supplier to customer. Starting from on

PAT 甲级 1106 Lowest Price in Supply Chain (25分) (bfs)

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 b

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 pric

PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)

简单dfs #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; const int maxn=100000+10; vector<int>g[m

1090. Highest Price in Supply Chain (25)【树】——PAT (Advanced Level) Practise

题目信息 1090. Highest Price in Supply Chain (25) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone involved in moving a product from supplier to customer. Starting from o

pat1090. Highest Price in Supply Chain (25)

1090. Highest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to

PAT 1090 Highest Price in Supply Chain[较简单]

1090 Highest 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 bu

PAT 1090. Highest Price in Supply Chain (25)(DFS啊 )

题目链接:http://www.patest.cn/contests/pat-a-practise/1090 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 o