1106 Lowest Price in Supply Chain

Posted keep23456

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }

技术图片

 

以上是关于1106 Lowest Price in Supply Chain的主要内容,如果未能解决你的问题,请参考以下文章

1106 Lowest Price in Supply Chain (25 分)dfs

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

PAT甲级——A1106 Lowest Price in Supply Chain

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

1106 Lowest Price in Supply Chain

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