PAT甲1106 Lowest Price in Supply Chain

题意

供货商,中间商和零售商每层都会加价,找到最便宜的零售商

题解

dfs找到深度最浅的零售商

源码

#include<cstring> 
#include<cmath>
#include<map>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
vector<int>mp[100005];
int visit[100005];
vector<int>retailer;
void dfs(int x,int depth){
	if(mp[x].size()==0){
		retailer.push_back(depth);
	}
	for(int i=0;i<mp[x].size();i++){
		if(visit[mp[x][i]]==0){
			visit[mp[x][i]]=1;
			dfs(mp[x][i],depth+1);
		}
	}
}
bool cmp(int x,int y){
	return x<y;
}
int main(){
	int n;
	double p,r;
	memset(visit,0,sizeof(visit));
	cin>>n>>p>>r;
	for(int i=0;i<n;i++){
		int len;
		cin>>len;
		while(len--){
			int x;
			cin>>x;
			mp[i].push_back(x);
		}
	}
	visit[0]=1;
	dfs(0,1);
	sort(retailer.begin(),retailer.end(),cmp);
	int pre=retailer[0];
	int counter=1;
	for(int i=1;i<retailer.size();i++){
		if(retailer[i]==pre){
			counter++;
		}else{
			break;
		}
	}
	cout<<fixed<<setprecision(4)<<p*pow(1+r/100,retailer[0]-1)<<" "<<counter<<endl;
	return 0; 
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值