PAT A1106 Lowest Price in Supply Chain

问题链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805362341822464

题意:

    给出一棵销售供应树,树根唯一。在树根处货物的价格为P,然后从根结点开始每往子结点走一层,该层的货物价格将会在父亲结点的价格上增加r%。求叶子结点处能获得的最低价格,以及能提供最低价格的叶子结点个数。

Note:

1 本题深度初始值为0。

2  r是百分号 要注意除以100

#include<cstdio>
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
const int maxn = 100010;
int n;
double p, r;
vector<int> child[maxn];
int lownum = 0;
int lowdepth = maxn;

void DFS(int index, int depth){
	if(child[index].size() == 0){
		if(depth < lowdepth){
			lowdepth = depth;
			lownum = 1;
		}else if(depth == lowdepth){
			lownum ++;
		}
	}
	for(int i = 0; i < child[index].size(); i++)
		DFS(child[index][i], depth + 1);
}
int main(){
	
	int k, x;
	cin >> n >> p >> r;
	
	for(int i = 0; i < n; i++){
		cin >> k;
		for(int j = 0; j < k; j++)
		{
			cin >> x;
			child[i].push_back(x);
		}
	}
	DFS(0, 0);
	
	r /= 100;
	printf("%.4f %d",p * pow(1+r, lowdepth), lownum);
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值