博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1079. Total Sales of Supply Chain (25)
阅读量:5275 次
发布时间:2019-06-14

本文共 2532 字,大约阅读时间需要 8 分钟。

A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.

Starting from one root supplier, everyone on the chain buys products from one's supplier in a price P and sell or distribute them in a price that is r% higher than P. Only the retailers will face the customers. It is assumed that each member in the supply chain has exactly one supplier except the root supplier, and there is no supply cycle.

Now given a supply chain, you are supposed to tell the total sales from all the retailers.

Input Specification:

Each input file contains one test case. For each case, the first line contains three positive numbers: N (<=105), the total number of the members in the supply chain (and hence their ID's are numbered from 0 to N-1, and the root supplier's ID is 0); P, the unit price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then N lines follow, each describes a distributor or retailer in the following format:

Ki ID[1] ID[2] ... ID[Ki]

where in the i-th line, Ki is the total number of distributors or retailers who receive products from supplier i, and is then followed by the ID's of these distributors or retailers. Kj being 0 means that the j-th member is a retailer, then instead the total amount of the product will be given after Kj. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print in one line the total sales we can expect from all the retailers, accurate up to 1 decimal place. It is guaranteed that the number will not exceed 1010.

Sample Input:

10 1.80 1.003 2 3 51 91 41 70 72 6 11 80 90 40 3

Sample Output:

42.4 解题思路:本题主要是利用邻接表来对供应链关系的记录,如图1所示,所给测试例子中,用一个vector来记录每个供应链中的价格分布(原价假设为0),0->2,时,2的价格变为0的1.01倍(r==0.01),当1->9时,9的价格为1的1.01倍,但由于此时1的价格未定,所以利用邻接表先存储1->9的关系,单5->1时,1的价格确定了,即可利用邻接表对和1临接的进行更新,更新9的价格为1.03:

图 1

#include
#include
#include
#include
using namespace std;struct Node{ vector
next;};vector
price;map
result;vector
vt;void update(int num,int r){ if(vt[num].next.empty())return; if(result.find(num)!=result.end())return ; vector
cur=vt[num].next; int size=cur.size(); for(int i=0;i
::iterator it=result.begin();it!=result.end();it++){ sum=sum+price[it->first]*it->second; } printf("%.1lf\n",sum); return 0;}

  

转载于:https://www.cnblogs.com/grglym/p/7922417.html

你可能感兴趣的文章
自定义返回模型
查看>>
C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - 客户端多网络支持
查看>>
HDU 4122
查看>>
Suite3.4.7和Keil u3自带fx2.h、fx2regs.h文件的异同
查看>>
打飞机游戏【来源于Crossin的编程教室 http://chuansong.me/account/crossincode 】
查看>>
[LeetCode] Merge Intervals
查看>>
【翻译自mos文章】当点击完 finishbutton后,dbca 或者dbua hang住
查看>>
Linux编程简介——gcc
查看>>
2019年春季学期第四周作业
查看>>
MVC4.0 利用IActionFilter实现简单的后台操作日志功能
查看>>
rotate the clock
查看>>
bugku 变量
查看>>
Python 环境傻瓜式搭建 :Anaconda概述
查看>>
数据库01 /Mysql初识以及基本命令操作
查看>>
数据库02 /MySQL基础数据类型以及多表之间建立联系
查看>>
Python并发编程04/多线程
查看>>
CF461B Appleman and Tree
查看>>
CF219D Choosing Capital for Treeland
查看>>
杂七杂八的小笔记本
查看>>
51Nod1353 树
查看>>