和下面是同类型的题目,只不过问的不一样罢了:

1090. Highest Price in Supply Chain (25)-dfs求层数

1106. Lowest Price in Supply Chain (25)-(dfs计算树的最小层数)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <cmath>
using namespace std;
/*
计算最小的层数与该层数上的叶子节点数目即可
建树用的是链式前向星模板,不了解的参考:
http://www.cnblogs.com/chenxiwenruo/p/4513754.html
*/
const int maxn=100000+5;
int product[maxn];
int head[maxn];
int tot=0;
double sum=0,p,r;
int cnt=0;
struct Edge{int to,next;
}edge[maxn];
void add(int x,int y){edge[tot].next=head[x];edge[tot].to=y;head[x]=tot++;
}
void init(){memset(head,-1,sizeof(head));tot=0;
}void dfs(int i,int layer){if(head[i]==-1){sum+=product[i]*p*pow(1+r/100,layer);return;}for(int k=head[i];k!=-1;k=edge[k].next){int v=edge[k].to;dfs(v,layer+1);}
}
int main()
{int n;scanf("%d %lf %lf",&n,&p,&r);int a,b;memset(product,0,sizeof(product));init();for(int i=0;i<n;i++){scanf("%d",&a);if(a==0){scanf("%d",&product[i]);}for(int j=0;j<a;j++){scanf("%d",&b);add(i,b);}}dfs(0,0);printf("%.1lf",sum);return 0;
}

View Code

转载于:https://www.cnblogs.com/chenxiwenruo/p/6390154.html

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

  1. 1079. Total Sales of Supply Chain (25)-PAT甲级真题(dfs,bfs,树的遍历)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  2. PAT甲级 -- 1079 Total Sales of Supply Chain (25 分)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  3. 1079. Total Sales of Supply Chain (25)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  4. 1079 Total Sales of Supply Chain(甲级)

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

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

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

  6. PAT甲级1079 Total Sales of Supply Chain:[C++题解] 树、结点到根结点的距离、树形dp、记忆化搜索

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析:下图是对样例的模拟图示,题目就是统计叶子结点卖出去的钱数.根据下图,我们第一步是建树,第二步是统计叶子结点到根结点的距离,然后才能知道 ...

  7. PAT 1079. Total Sales of Supply Chain

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  8. 1079 Total Sales of Supply Chain

    1. 这道题考察的是树的层次遍历,结点需要有层这个属性,对于我来说,难点在于什么时候给层赋值,看书后知道应该是在加入队列之前(不管是根节点还是之后所有节点). 2. 一开始算得216,原因是把r直接加 ...

  9. 【PAT】A1079 Total Sales of Supply Chain

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  10. 分别采用递归和非递归方式编写两个函数,求一棵二叉树中叶子节点个数

    分别采用递归和非递归方式编写两个函数,求一棵二叉树中叶子节点个数 #include #include #define MAXSIZE 50 typedef char datatype; typedef ...

最新文章

  1. 最大子序和的golang实现
  2. SpringBoot + Vue + nginx项目一起部署
  3. css-modules 简介
  4. Git+SourceTree使用时出现的问题
  5. python中的re模块和正则表达式基础
  6. ejb能调用另一个ejb吗_异步EJB只是一个Gi头吗?
  7. http:(3):http响应头信息
  8. 我用Python爬取1000封情书助力室友表白班花,却反转再反转...原来这就是班花的终极秘密!
  9. Linux shell脚本详解及实战(一)——shell简介、shell变量及脚本规范
  10. 基于visual Studio2013解决C语言竞赛题之1030计算函数
  11. 阶段3 2.Spring_08.面向切面编程 AOP_3 spring基于XML的AOP-编写必要的代码
  12. 常用html元素的取值和赋值方法总结
  13. 欧派caxa设计软件_欧派与数码大方携手,CAXA智能家居设计软件引领家居变革
  14. 传感器网络知识点总结
  15. 如何生成token,是使用token
  16. 001-SE-0011-网络编程
  17. ubuntu 8.04.2
  18. Windows:win10中查看自己的电脑版本号的五种方法
  19. 分享一下阿里云的maven镜像地址(速度贼快的那种)
  20. oppo安卓面试题,Android插件化入门指南,含泪整理面经

热门文章

  1. Unity脚本中查找的几种方法优劣以及坑
  2. 分布式系统设计时,遵循CAP原则
  3. c语言数组字节偏移,C语言数组中的地址偏移问题
  4. JAVA if语句快捷键_java编程基础 第一、第二章
  5. 单片机,嵌入式,PLC三者之间有什么区别,学习方向如何选择
  6. 【渝粤题库】陕西师范大学500901 基础物理专题(力、热) 作业(专升本)
  7. Linux系统(七)组管理和用户管理
  8. 强化学习实战(四)基于强化学习的倒立摆控制策略Matlab实现(附代码) 二刷
  9. Lecture 3:动态规划
  10. Redis NOAUTH Authentication required