PAT.A1106 Lowest Price in Supply Chain

返回目录

在这里插入图片描述

题意

给出一颗销售供应的树,树根唯一。树根价格为p,然后从根节点开始,每向下一层,价格上涨r%。求所有叶节点中能获得的最低价格和最低价格的叶节点个数。

样例(可复制)

10 1.80 1.00
3 2 3 5
1 9
1 4
1 7
0
2 6 1
1 8
0
0
0
//output
1.8362 2

注意点

  1. 本题与A1090非常类似,那题求的是最高价格,本题求的是最低价格
  2. 根节点深度为0
#include<bits/stdc++.h>
using namespace std;


int n,m,tmp,mindepth=100010,num=0;
double p,r; 
vector<int> node[100010];
void DFS(int root,int depth){
	if(node[root].size()==0){
		if(depth==mindepth)num++;
		if(depth<mindepth){
			mindepth=depth;
			num=1;
		}
	}
	for(int i=0;i<node[root].size();i++){
		DFS(node[root][i],depth+1);
	}
}
int main(){
	cin>>n>>p>>r;
	r/=100;
	for(int i=0;i<n;i++){
		scanf("%d",&m);
		while(m--){
			scanf("%d",&tmp);
			node[i].push_back(tmp);
		}
	}
	DFS(0,0);
	printf("%.4f %d",p*pow(1+r,mindepth),num);
    return 0;
}
发布了177 篇原创文章 · 获赞 5 · 访问量 6668

猜你喜欢

转载自blog.csdn.net/a1920993165/article/details/105505055