第二天PAT-A1106 Lowest Price in Supply Chain

A1106

Description:

在将产品从供应商流通至消费者的过程中包含零售商、经销商和供应商三个角色。

从一个根供应商起,每人将价格定位进价的(100+r)%,只有零售商会面对消费者。保证供应链上的每个校色只有一个供应商(除了根供应商)。

给一个供应链,求消费者可以从零售商手中获得的最低价格。

同系列题目:

代码采用广搜查找问题答案:

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
using namespace std;
const int maxn = 1e5+5;

struct node{
    int level;
    vector<int>child;   //孩子节点
}Node[maxn];

double price, r;
int n;
int cnt[maxn];
int minlevel = maxn;

void bfs(){
    queue<int>q;
    q.push(0);  //将根节点入队
    while(!q.empty()){
        if(Node[q.front()].child.empty()){  //孩子节点为空,零售商节点
            cnt[Node[q.front()].level]++;
            if(Node[q.front()].level < minlevel)
                minlevel = Node[q.front()].level;
        }
        for(vector<int>::iterator it = Node[q.front()].child.begin();
            it != Node[q.front()].child.end(); it++){
            Node[*it].level = Node[q.front()].level + 1;
            q.push(*it);
        }
        q.pop();
    }
}

int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
    scanf("%d%lf%lf", &n, &price, &r);
    r /= 100;
    int tchild, temp;
    for(int i = 0; i < n; i++){
        scanf("%d", &tchild);
        for(int j = 0; j < tchild; j++){
            scanf("%d", &temp);
            Node[i].child.push_back(temp);
        }
    }
    Node[0].level = 0;
    bfs();
    printf("%.4f %d\n", price*pow(1+r, minlevel), cnt[minlevel]);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值