pat 1079
来源:互联网 发布:赢商网怎么样知乎 编辑:程序博客网 时间:2024/05/22 11:35
the key point is how to present a tree....data structure
ps:time and space complexity.
#include<iostream>using namespace std;struct TreeNode{double price;int parent;int amount;};int main(){const int N=100001;TreeNode node[N];int n;double p,r;cin>>n>>p>>r;for(int i=0;i<n;i++){node[i].price=0;node[i].amount=0;}node[0].price=p;for(int i=0;i<n;i++){int k;cin>>k;if(k==0){cin>>node[i].amount;}else{for(int j=0;j<k;j++){int x;cin>>x;node[x].parent=i;if(node[i].price!=0){node[x].price=node[i].price*(1+r/100);}}}}double ans=0;for(int i=0;i<n;i++){if(node[i].price==0){node[i].price=node[node[i].parent].price*(1+r/100);}if(node[i].amount!=0){ans+=node[i].price*node[i].amount;}}printf("%.1lf",ans);}
0 0
- pat 1079
- pat 1079
- pat 1079
- PAT 1079
- pat 1079
- PAT Advanced Level 1079
- pat 1079 another solution
- PAT(甲级)1079
- *浙大PAT甲级 1079
- PAT甲级1079
- pat
- 【PAT】
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- 3D数学读书笔记——多坐标系和向量基础
- Android自动化HTML报告
- 【读书笔记】学习OpenCV(中文版)第二章
- 【微软编程一小时】题目1 : Arithmetic Expression
- 命令行执行不回显不提示
- pat 1079
- i.max6 e9 android系统添加3G模块支持 上
- Android MID 3G 移植
- PAT - 1021. 个位数统计 (15)
- mfc 线程与进程
- 【tomcat】启动时报错问题
- 【数学】HDU 1222 Wolf and Rabbit
- 拦截器与过滤器
- Codeforces Round #243 (Div. 1)-A,B,C-D