【PAT甲级】1106 Lowest Price in Supply Chain (25分)
题意:
输入一个正整数N(<=1e5),两个小数P和R,分别表示树的结点个数和商品原价以及每下探一层会涨幅的百分比。输出叶子结点深度最小的商品价格和深度最小的叶子结点个数。
trick:
测试点1只有根节点一个点,输出P和1。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
vector<int>v[];
int store[];
void dfs(int x,int y){
if(v[x].size()==)
store[x]=y;
for(auto it:v[x]){
dfs(it,y+);
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
double p,r;
cin>>p>>r;
for(int i=;i<n;++i){
int x;
cin>>x;
for(int j=;j<=x;++j){
int y;
cin>>y;
v[i].push_back(y);
}
}
dfs(,);
int mn=1e9;
for(int i=;i<n;++i)
if(store[i])
mn=min(mn,store[i]);
int num=;
if(mn==1e9)
mn=;
for(int i=;i<n;++i)
if(store[i]==mn)
++num;
double ans=pow(1.0+r/,mn);
ans*=p;
printf("%.4lf %d",ans,num);
return ;
}
【PAT甲级】1106 Lowest Price in Supply Chain (25分)的更多相关文章
- 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 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( ...
- 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 ...
- PAT甲级——A1106 Lowest Price in Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- 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)-(dfs计算树的最小层数)
统计树的最小层数以及位于该层数上的叶子节点个数即可. 代码里建树我用了邻接链表的存储方式——链式前向星,不了解的可以参考,非常好用: http://www.cnblogs.com/chenxiwenr ...
随机推荐
- PHP实现微信公众号授权获取用户信息
class WxAuthModel extends BaseModel { var $appId = APPID; var $appSecret = APPSECRET; /*微信x小程序,获取微信o ...
- MyEclipse 运行弹出A Java Exception has occurred.
问题描述 A Java Exception has occurred. 问题原因 这个问题是由较高版本的JDK编译的java class文件试图在较低版本的JVM上运行而产生的错误
- Python-selenium,使用SenKey模块时所碰到的坑
一.SenKey模块(模拟鼠标键盘操作) :python3中没有该模块,使用PyUserInput模块代替 二.PyUserInput模块安装前需要安装:pywin32和pyHook模块,pywin3 ...
- HTML span标签
span:行内标签,不会换行用于:组合文档中的行内元素.元素和文档的组合
- centos python版本升级到3.x
Linux(CentOS)下将Python的版本升级为3.6.2的方法 1.检查确认系统的相关信息 查看内核版本[root@zstest1 ~]# cat /etc/redhat-release Ce ...
- Mybaits的中的对象映射(包含仅有基本数据类型的属性的和对象类型的属性的)
转:https://blog.csdn.net/cjt20100/article/details/46547617. 1 constructor – 用来将结果反射给一个实例化好的类的构造器 a ...
- appium---webview(H5)元素定位
我们在做UI自动化的时候,肯定需要元素定位,那么webview(H5)的元素怎么定位呢? webview定位方法 方法一: 1.打开chrome浏览器,输入chrome://inspect 2.连接手 ...
- 结构struct 联合Union和枚举Enum的细节讨论
联合(Union)是一种构造数据类型,它提供了一种使不同类型数据类型成员之间共享存储空间的方法,同时可以实现不同类型数据成员之间的自动类型转换.联合体对象在同一时间只能存储一个成员的值.联合的内存大小 ...
- crontab实践
1.crontab概要 2.crontab使用 3.关键配置信息 3.1如何配置定时任务 4.注意事项 参考 https://www.cnblogs.com/keithtt/p/6946498.htm ...
- EQ实现
原理参考: https://www.cnblogs.com/fellow1988/p/9189338.html https://www.cnblogs.com/fellow1988/p/9136346 ...