PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)

Posted Fighting Heart

tags:

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

简单dfs

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

const int maxn=100000+10;
vector<int>g[maxn];
int n;
double P,r;
int ans_count=0;
double ans_price=99999999;

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

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

int main()
{
    scanf("%d",&n);
    scanf("%lf%lf",&P,&r);
    for(int i=0;i<n;i++)
    {
        int num; scanf("%d",&num);
        while(num--)
        {
            int x; scanf("%d",&x);
            g[i].push_back(x);
        }
    }

    dfs(0,P);

    printf("%.4lf %d\n",ans_price,ans_count);

    return 0;
}

 

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

PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)

1106. Lowest Price in Supply Chain (25)树+深搜——PAT (Advanced Level) Practise

1106. Lowest Price in Supply Chain (25)树+深搜——PAT (Advanced Level) Practise

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

PAT Advanced Level 1044

PAT Advanced Level 1043