#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <map>
#include <queue>
#include <math.h>
using namespace std;
struct node
{
double price;
int level;
vector<int> child;
bool r;
int snum;
}A[100010];
int N;
double start,p;
double total=0;
void levelorder(int st)
{
queue<int> q;
q.push(st);
int level=0;
int preend=st,last=st;
while(!q.empty())
{
int top=q.front();
q.pop();
A[top].level=level;
if(A[top].r)
{
A[top].price=start*pow(p,level);
total+=A[top].price*A[top].snum;
}
for(int i=0;i<A[top].child.size();i++)
{
q.push(A[top].child[i]);
last=A[top].child[i];
}
if(top==preend)
{
preend=last;
level++;
}
}
}
int main()
{
scanf("%d %lf %lf",&N,&start,&p);
p=1+p/100;
for(int i=0;i<N;i++)
{
int num;
scanf("%d",&num);
if(num>0)
{
for(int j=0;j<num;j++)
{
int p;
scanf("%d",&p);
A[i].child.push_back(p);
}
A[i].r=false;
}
else
{
A[i].r=true;
scanf("%d",&A[i].snum);
}
}
levelorder(0);
printf("%.1f",total);
return 0;
}
PAT甲1079 Total Sales of Supply Chain(25 分)

最新推荐文章于 2024-08-06 23:56:01 发布
