PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)

Posted Fighting Heart

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)相关的知识,希望对你有一定的参考价值。

简单dfs。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;

const int maxn=100000+10;
vector<int>g[maxn];
int n;
double p,r;
int root;
int ans_x;
double ans_price=0;

void dfs(int x,double price)
{
    if(g[x].size()==0)
    {
        if(price>ans_price)
        {
            ans_price=price;
            ans_x=1;
        }
        else if(price==ans_price)
        {
            ans_x++;
        }
        return;
    }

    for(int i=0;i<g[x].size();i++)
    {
        dfs(g[x][i],price*(1.0+r/100));
    }
}

int main()
{
    scanf("%d",&n);
    scanf("%lf%lf",&p,&r);

    for(int i=0;i<n;i++)
    {
        int fa; scanf("%d",&fa);
        if(fa==-1) root=i;
        else g[fa].push_back(i);
    }

    dfs(root,p);

    printf("%.2lf %d\n",ans_price,ans_x);

    return 0;
}

 

以上是关于PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)的主要内容,如果未能解决你的问题,请参考以下文章

1090. Highest Price in Supply Chain (25)树——PAT (Advanced Level) Practise

PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)

PAT (Advanced Level) 1025. PAT Ranking (25)

PAT Advanced Level 1044

PAT Advanced Level 1043

PAT Advanced Level 1079