pat 1079. Total Sales of Supply Chain(树模拟)
来源:互联网 发布:linux可执行文件格式 编辑:程序博客网 时间:2024/06/05 04:38
偏简单的题目
注意考虑N=1的特殊情况
用BFS求根叶距离(如果暴力从每个叶结点回溯的话会超时)
#include<stdio.h>#include<math.h>#include<vector>#include<queue>using namespace std;int number[100005];int lev[100005];vector<int> vs[100005];queue<int> q;int main(){int n,num,j,i,x,y,l,sz;double p,r;scanf("%d%lf%lf",&n,&p,&r);for(i=0;i<n;i++){scanf("%d",&num);if(num){for(j=0;j<num;j++){scanf("%d",&x);vs[i].push_back(x);}}else{scanf("%d",&x);number[i]=x;}}q.push(0);while(!q.empty()){y=q.front();sz=vs[y].size();for(l=0;l<sz;l++){lev[vs[y][l]]=lev[y]+1;q.push(vs[y][l]);} q.pop();}double sum=0,per;if(n==1){sum=p*number[0];printf("%.1lf\n",sum);return 0;}for(i=0;i<n;i++){if(number[i]){per=1+r/100;sum+=pow(per,lev[i])*number[i];}}sum*=p;printf("%.1lf\n",sum);return 0;}
0 0
- pat 1079. Total Sales of Supply Chain(树模拟)
- 【PAT】1079. Total Sales of Supply Chain
- PAT--1079. Total Sales of Supply Chain
- pat 1079 Total Sales of Supply Chain
- PAT 1079. Total Sales of Supply Chain (25)
- PAT (Advanced) 1079. Total Sales of Supply Chain (25)
- PAT Advanced Level 1079. Total Sales of Supply Chain (25)
- PAT A 1079. Total Sales of Supply Chain (25)
- PAT 1079. Total Sales of Supply Chain (25)
- PAT 1079. Total Sales of Supply Chain (25)
- PAT 1079. Total Sales of Supply Chain (25)
- 【PAT】1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)PAT甲级
- PAT甲级练习1079. Total Sales of Supply Chain (25)
- PAT-A-1079. Total Sales of Supply Chain (25)
- 【PAT甲级】1079. Total Sales of Supply Chain (25)
- 【PAT】【Advanced Level】1079. Total Sales of Supply Chain (25)
- PAT 甲级 1079. Total Sales of Supply Chain (25)
- Spring +Struts2+ibatis 整合细节
- windows shell
- Webdriver - how to view log(grid mode)
- Android的四种启动模式
- Python 中调用函数的Docstring
- pat 1079. Total Sales of Supply Chain(树模拟)
- Nginx中队列使用学习
- [Java 8] (10) 使用Lambda完成函数组合,Map-Reduce以及并行化
- Android中Activity启动模式详解
- Const,Const函数,Const变量,函数后面的Const
- Spring Security管理下的ajax请求登录超时问题处理
- java使用三个线程,按顺序线程1输出1、线程2输出2、线程3输出3
- LD_PRELOAD环境变量
- Swoole源码学习记录(十五)——Timer模块分析