1106. Lowest Price in Supply Chain (25)

题目详情:https://www.patest.cn/contests/pat-a-practise/1106

提交情况:这里写图片描述

提交代码:

#include <iostream>
#include <string.h>
#include <vector>
#include <math.h>
using namespace std;
#define Max 100010
#define INF 0x3f3f3f3f
vector<int> child[Max];
int root[Max],Root,depth,visit[Max],n,depths[Max];
double rootPrice,percent;
void DFS( int vertex ,int depth )
{
    visit[vertex] = 1;
    depths[vertex] = depth; //得到节点的深度 
    for( int i=0;i<child[vertex].size();++i )
    {
        int key = child[vertex][i];
        if( visit[key] == 0 )
        {
            ++depth;  //跟踪节点的深度 
            DFS(key,depth);
            --depth;
        }       
    }
}
int main()
{
    cin>>n>>rootPrice>>percent;
    for( int i=0;i<n;++i )  //输入处理 
    {
        int num;
        cin>>num;
        for( int j=0;j<num;++j )
        {
            int kid;
            cin>>kid;
            child[i].push_back(kid);
        }
    }
//  cout<<"Root is "<<Root<<endl;
    depth = 1;
    DFS(0,depth);
    int minDepth = INF,number = 0;
    for( int i=0;i<n;++i )  //得到最大的深度,并用number记录最大深度的个数 
    {
        if( child[i].size()==0 && depths[i] < minDepth )
        {
            minDepth = depths[i];
            number = 1;
        }
        else if ( child[i].size()==0 && depths[i] == minDepth )
        {
            ++number;
        }
        //以下代码查看各节点的深度 
//      if( i == n-1 )
//          cout<<depths[i]<<endl;
//      else
//          cout<<depths[i]<<" ";
    }
    printf("%.4lf %d",rootPrice*pow(1+percent/100,minDepth-1),number);
    return 0;
} 

最什么好说,和1079题,1090题都差不多,一个求最高的售价,最低的售价和总的销售额。本题求最低售价,1090题求最高售价,1079求总的销售额。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值