PAT (Advanced Level) 1079. Total Sales of Supply Chain (25)
树的遍历。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std; const int maxn=+;
vector<int>tree[maxn];
int n;
double P,r;
double sum;
int sz;
int num[maxn]; void dfs(int x,double price)
{
if(tree[x].size()==)
{
sum=sum+num[x]*price;
sz++;
return;
} for(int i=;i<tree[x].size();i++)
dfs(tree[x][i],price*(+r/)*1.0);
}
int main()
{
scanf("%d",&n);
scanf("%lf%lf",&P,&r);
for(int i=;i<n;i++)
{
int ki; scanf("%d",&ki); if(ki==)
{
int x; scanf("%d",&x);
num[i]=x;
}
else
{
while(ki--)
{
int to; scanf("%d",&to);
tree[i].push_back(to);
}
}
} sum=;sz=;
dfs(,P);
printf("%.1lf\n",sum); return ;
}
PAT (Advanced Level) 1079. Total Sales of Supply Chain (25)的更多相关文章
- 【PAT甲级】1079 Total Sales of Supply Chain (25 分)
题意: 输入一个正整数N(<=1e5),表示共有N个结点,接着输入两个浮点数分别表示商品的进货价和每经过一层会增加的价格百分比.接着输入N行每行包括一个非负整数X,如果X为0则表明该结点为叶子结 ...
- 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 ...
- 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 ...
- 1079. Total Sales of Supply Chain (25)-求数的层次和叶子节点
和下面是同类型的题目,只不过问的不一样罢了: 1090. Highest Price in Supply Chain (25)-dfs求层数 1106. Lowest Price in Supply ...
- PAT Advanced 1079 Total Sales of Supply Chain (25) [DFS,BFS,树的遍历]
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...
- 1079. Total Sales of Supply Chain (25)
时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...
- 1079. Total Sales of Supply Chain (25) -记录层的BFS改进
题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...
- PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)
简单dfs #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)
简单dfs. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
随机推荐
- CATransform3D的使用以及各个参数的含义
1. 缩放 CABasicAnimation *theAnimation=[CABasicAnimation animationWithKeyPath:@"transform"]; ...
- Linux 任务控制(bg job fg nohup &)
一. 简介 Linux/Unix 区别于微软平台最大的优点就是真正的多用户,多任务.因此在任务管理上也有别具特色的管理思想.我们知道,在 Windows 上面,我们要么让一个程序作为服务在后台 ...
- python socketserver实现客户端多并发
直接看代码 server #!/usr/bin/env python # -*- coding:utf-8 -*- import socketserver import subprocess clas ...
- String s = new String("aa") 创建了几个对象?
1 最近几个同学面试的时候出现了这样一个问题 刚听到这个题目的时候的确是不知所措: 经过网上的查找和自己的理解来解释一下这个题目的答案 答案是: 为什么呢??? 1 实现我们都知道创建实例有两种方法 ...
- LA 4329 BIT 分治
#include <cstdio> #include <queue> #include <cstring> #include <iostream> #i ...
- jsp base标签与meta标签学习小结
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...
- java复用类
java复用类英文名叫reusing classes ,重新使用的类,复用的意思就是重复使用的类,其实现方法就是我们平常使用的组合和继承: 1.组合: has-a 的关系 (自我理解:组合就是我们 ...
- HDU1253--胜利大逃亡--HDU1240--Asteroids!--简单三维BFS
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- Lucene.NET中Field.Index 和 Field.Store的几种属性的用法
转载自 http://blog.csdn.net/yja886/article/details/6612069 lucene在doc.add(new Field("content" ...
- Django -- Views and URLconf
1 创建工程 django-admin startproject mysite && cd mysite 2 创建应用 python manage.py startapp blog 3 ...