PAT甲题题解-1106. Lowest Price in Supply Chain (25)-(dfs计算树的最小层数)
统计树的最小层数以及位于该层数上的叶子节点个数即可。
代码里建树我用了邻接链表的存储方式——链式前向星,不了解的可以参考,非常好用:
http://www.cnblogs.com/chenxiwenruo/p/4513754.html
#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=+;
int head[maxn];
int tot=;
int minlayer=maxn;
int cnt=;
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,-,sizeof(head));
tot=;
} void dfs(int i,int layer){
if(head[i]==-){
if(layer<minlayer){
cnt=;
minlayer=layer;
}
else if(layer==minlayer){
cnt++;
}
return;
}
for(int k=head[i];k!=-;k=edge[k].next){
int v=edge[k].to;
dfs(v,layer+);
}
}
int main()
{
int n;
double p,r;
scanf("%d %lf %lf",&n,&p,&r);
int a,b;
init();
for(int i=;i<n;i++){
scanf("%d",&a);
for(int j=;j<a;j++){
scanf("%d",&b);
add(i,b);
}
}
dfs(,);
double sum=p;
for(int i=;i<minlayer;i++){
sum*=(+r/);
}
printf("%.4lf %d",sum,cnt);
return ;
}
PAT甲题题解-1106. Lowest Price in Supply Chain (25)-(dfs计算树的最小层数)的更多相关文章
- PAT Advanced 1106 Lowest Price in Supply Chain (25) [DFS,BFS,树的遍历]
题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone in ...
- [建树(非二叉树)] 1106. Lowest Price in Supply Chain (25)
1106. Lowest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors( ...
- 1106. Lowest Price in Supply Chain (25)
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)
简单dfs #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- 【PAT甲级】1106 Lowest Price in Supply Chain (25分)
题意:输入一个正整数N(<=1e5),两个小数P和R,分别表示树的结点个数和商品原价以及每下探一层会涨幅的百分比.输出叶子结点深度最小的商品价格和深度最小的叶子结点个数. trick: 测试点1 ...
- PAT甲级——1106 Lowest Price in Supply Chain(BFS)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90444872 1106 Lowest Price in Supp ...
- PAT 甲级 1106 Lowest Price in Supply Chain
https://pintia.cn/problem-sets/994805342720868352/problems/994805362341822464 A supply chain is a ne ...
- PAT 1106 Lowest Price in Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- PAT甲题题解-1006. Sign In and Sign Out (25)-找最小最大
判断哪个人最早到,哪个人最晚走水,就是找最大值最小值 #include <iostream> #include <cstdio> #include <algorithm& ...
随机推荐
- 系统升级win7 sp1后,ado,MSJRO.tlh error 问题
MSJRO.tlh() : error C2501: '_RecordsetPtr' : missing storage-class or type specifiers MSJRO.tlh() : ...
- node.js 笔记一
现在地址:http://nodejs.org/download/ 我的机器是windows的,选择的文件是,是编译后的版本:Windows Installer (.msi) 32-bit examp ...
- Alpha冲刺报告(3/12)(麻瓜制造者)
今日已完成情况: 肖小强: 解决了之前的部署demo问题,学习了基本需要的api 江郑: 进行发布需求数据库的增删改查 邓弘立: 完成了轮播图的设计 刘双玉: 编码发布商品的接口,数据库表的修改 汪志 ...
- ffmpeg常用参数一览表
基本选项: -formats 输出所有可用格式 -f fmt 指定格式(音频或视频格式) -i filename 指定输入文件名,在linux下当然也能指定:0.0(屏幕录制)或摄像头 -y 覆盖已有 ...
- Python基础5
本节内容 1. 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4.递归 5.匿名函数 6.函数式编程介绍 7.高阶函数 8.内置函数 温故知新 1. 集合 主要作用: 去重 关系测 ...
- luogu P2365 任务安排
嘟嘟嘟 如果常规dp,\(dp[i][j]\)表示前\(i\)个任务分\(j\)组,得到 \[dp[i][j] = min _ {k = 0} ^ {i - 1} (dp[k][j - 1] + (s ...
- Qt Creator无法debug,报错:The selected debugger may be inappropriate for the inferior. Examining symbols and setting breakpoints by file name and line number may fail. The inferior is in the Portable ...
看到这个报错我是绝望的 解决:下载windows sdk win10 sdk 只安装Debugging Tools for Windows 打开 工具-选项-Kits 安装sdk成功后我们可以看到 ...
- Android检查手机上是否安装了第三方软件的方法------本文以百度地图为例
package com.example.myapi.thirdbaidumap; import java.net.URISyntaxException; import java.util.ArrayL ...
- MVC的BundleConfig类
在BundleConfig.cs文件中,包含了一些应用程序中使用的脚本和样式表的文件路径.并可以使用通配符.示例如下: using System.Web; using System.Web.Optim ...
- CAN2.0A 和CAN2.0B
CAN2.0A 和CAN2.0B 原创 2015年08月03日 16:03:08 3969 CAN2.0A 是CAN协议的PART A部分,此部分定义了11bit的标识区 .CAN2.0B 是CAN协 ...