AcWing 1565. 供应链总销售额
原题链接
简单
作者:
无敌的拖拉机
,
2024-10-24 20:57:40
,
所有人可见
,
阅读 2
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
using namespace std;
const int N = 1e5 + 10;
int n;
double price, r;
int head[N], p[N], s[N], d[N];
vector<int> vec;
double res;
void dfs(int r)//遍历树,求零售商到根节点的距离
{
for(int i = head[r]; i != -1; i = p[i])
{
d[i] = 1 + d[r];
dfs(i);
}
}
int main()
{
cin >> n >> price >> r;
for (int i = 0; i < n; i++)
head[i] = -1;
for (int i = 0; i < n; i++)
{
int t;
cin >> t;
if(t == 0)
{
int a;
cin >> a;
vec.push_back(i);//保存零售商的编号
s[i] = a;//保存零售商售卖产品数量
}
else
{
for(int j = 0; j < t; j++)
{
int b;
cin >> b;
p[b] = head[i];
head[i] = b;
}
}
}
dfs(0);
for(int i = 0; i < vec.size(); i++)
res += s[vec[i]] * price * pow(1 + r / 100, d[vec[i]]);
// 使用fixed和setprecision设置输出格式
cout << fixed << setprecision(1) << res << endl;
return 0;
}