时间限制
250 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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.00
3 2 3 5
1 9
1 4
1 7
0 7
2 6 1
1 8
0 9
0 4
0 3

Sample Output:

42.4
 #include<stdio.h>
#include<vector>
#include<math.h>
using namespace std; struct Node
{
int parent;
double val;
vector<int> child;
}; Node Tree[];
bool visit[]; double sum; void DFS(int root,int level,double price,double rate)
{
visit[root] = true;
if(Tree[root].child.empty())
{
sum += Tree[root].val * price*pow((+rate)/,level);
}
else
{
for(int i = ;i < Tree[root].child.size();i++)
{
if(visit[Tree[root].child[i]] == false)
DFS(Tree[root].child[i],level+,price,rate);
}
}
} int main()
{
int ID,pro,count,j,num,i;
double price,rate;
scanf("%d%lf%lf",&num,&price,&rate);
for( i = ; i < num ;i++)
{
Tree[i].child.clear();
Tree[i].parent = -;
visit[i]= false;
}
for(i = ;i < num ;i ++)
{
scanf("%d",&count);
if(count == )
{
scanf("%d",&pro);
Tree[i].val = pro;
}
else
{
for(j = ;j < count ;j++)
{
scanf("%d",&ID);
Tree[i].child.push_back(ID);
Tree[ID].parent = i;
}
}
} int root = ;
while(Tree[root].parent != -)
++root;
int level = ;
sum = ;
DFS(root,level,price,rate);
printf("%0.1lf\n",sum); return ;
}

1079. Total Sales of Supply Chain (25)的更多相关文章

  1. 1079. Total Sales of Supply Chain (25)【树+搜索】——PAT (Advanced Level) Practise

    题目信息 1079. Total Sales of Supply Chain (25) 时间限制250 ms 内存限制65536 kB 代码长度限制16000 B A supply chain is ...

  2. PAT 甲级 1079 Total Sales of Supply Chain (25 分)(简单,不建树,bfs即可)

    1079 Total Sales of Supply Chain (25 分)   A supply chain is a network of retailers(零售商), distributor ...

  3. 1079. Total Sales of Supply Chain (25)-求数的层次和叶子节点

    和下面是同类型的题目,只不过问的不一样罢了: 1090. Highest Price in Supply Chain (25)-dfs求层数 1106. Lowest Price in Supply ...

  4. 1079. Total Sales of Supply Chain (25) -记录层的BFS改进

    题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...

  5. PAT Advanced 1079 Total Sales of Supply Chain (25) [DFS,BFS,树的遍历]

    题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...

  6. PAT (Advanced Level) 1079. Total Sales of Supply Chain (25)

    树的遍历. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  7. 【PAT甲级】1079 Total Sales of Supply Chain (25 分)

    题意: 输入一个正整数N(<=1e5),表示共有N个结点,接着输入两个浮点数分别表示商品的进货价和每经过一层会增加的价格百分比.接着输入N行每行包括一个非负整数X,如果X为0则表明该结点为叶子结 ...

  8. pat1079. Total Sales of Supply Chain (25)

    1079. Total Sales of Supply Chain (25) 时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  9. PAT 1079 Total Sales of Supply Chain[比较]

    1079 Total Sales of Supply Chain(25 分) A supply chain is a network of retailers(零售商), distributors(经 ...

随机推荐

  1. 用DAEMON TOOLS打开rational ross 的bin文件并安装过程梳理

    最近要开始准备毕业设计了,学习熟悉了一些UML用例图.类图之类的,开始准备用自家PC电脑画图的时候发现Rational Ross没安装. 本以为简单,却碰上bin文件.琢磨好久,终于把Ross安上了. ...

  2. js中将字符串转换成json的方式

    1.eval 方式解析,实际中用的还是比较少 function evalJson(str){ var json = eval('(' + str + ')'); return json; } 2.使用 ...

  3. CEF js调用C#封装类含注释

    /* * CEF JS调用C#组装类 * * 使用方法(CefGlue为例): * public class BrowserRenderProcessHandler : CefRenderProces ...

  4. 乐在其中设计模式(C#) - 代理模式(Proxy Pattern)【转】

    介绍 为其他对象提供一个代理以控制对这个对象的访问. 示例 有一个Message实体类,某对象对它的操作有Insert()和Get()方法,用一个代理来控制对这个对象的访问. MessageModel ...

  5. Telnet客户端连接服务器,看不见字符,只显示横线

    Telnet 窗口看不见字符,只显示小横线 在用telnet连接tomcat服务器的 时候,窗口中不显示字符,显示成一个一个的横线 解决办法: 按住“Ctrl+]” 回车解决问题

  6. Linux时间函数

    一.时间编程 1.核心理论 (1).时间类型 2.函数学习 (1).获取日历时间 函数名:time 函数原型:time_t time(time_t *t) 函数功能:获取当前日历时间 所属头文件:&l ...

  7. 初识Less(2015年05月23日)

    因为最近在研究Bootstrap,然后才了解到Less,听说Less很强大,又听说Bootstrap+Less会更搭,所以就决定也顺带了解下Less的相关知识. come  on...... 一.简介 ...

  8. MyBatis(3.2.3) - Configuring MyBatis using XML, Settings

    The default MyBatis global settings, which can be overridden to better suit application-specific nee ...

  9. 做SqlDependency总结的一些经验

    1.--查询是否具有Broker功能  select is_broker_enabled from sys.databases where [name]='DBName' 2.--打开Broker功能 ...

  10. C# 使用Code First迁移更新数据库

    三步完成迁移: 1. 启用迁移: Enable-Migrations Enable-Migrations -ContextTypeName Mvc4WebSite.Models.MvcGuestboo ...