标签:clu oid bfs algorithm lse scan ack names ret
供应链有3种人,零售商,经销商和供应商,供应链上的人都可以从自己的供应商那里以P
的价格买入,而后以r%
的涨幅卖给下一级,问供应链上找零售商买价格最低是多少
BFS
和DFS
都可以做,DFS
代码量少我就用DFS
了#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
using namespace std;
int n;
vector<int> tree[100010];
double init_price, increment;
double ans_price;
int numbers = 0, ans_depth = 1000000000;
void dfs(int cur, int depth)
{
if(tree[cur].size() == 0)
{
if(depth < ans_depth)
{
ans_depth = depth;
numbers = 1;
}else if(depth == ans_depth)
numbers++;
}
for(int i=0;i<tree[cur].size();i++)
dfs(tree[cur][i], depth + 1);
}
int main()
{
cin >> n >> init_price >> increment;
increment /= 100;
int t, tmp;
for(int i=0;i<n;i++)
{
scanf("%d", &t);
if(t == 0)
continue;
else{
for(int j=0;j<t;j++)
{
scanf("%d", &tmp);
tree[i].emplace_back(tmp);
}
}
}
dfs(0, 0);
ans_price = init_price * pow(1 + increment, ans_depth);
printf("%.4f %d", ans_price, numbers);
return 0;
}
PAT(Advanced Level)A1106. Lowest Price in Supply Chain
标签:clu oid bfs algorithm lse scan ack names ret
原文地址:https://www.cnblogs.com/MartinLwx/p/13770977.html