zoukankan      html  css  js  c++  java
  • 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
    ",ans_price,ans_count);
    
        return 0;
    }
  • 相关阅读:
    Python 递归
    Python 面向过程编程
    Python 协程函数
    Python-第三方库requests详解
    Python 三元表达式
    linux copy
    centos 安装软件
    mysql 权限
    mysql 权限 备份
    android 开发
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5642481.html
Copyright © 2011-2022 走看看