pat 1079 another solution
2014-04-28 20:36
169 查看
this solution shows well in time and space complexity,but it exceeds limited time at last case.
even change cin to scanf.maybe there are some leaves that far away from the root.
even change cin to scanf.maybe there are some leaves that far away from the root.
#include<iostream> #include<cmath> using namespace std; struct _leaf { int amount; int index; }; int main() { // freopen("C:\\Users\\Frank Wang\\Desktop\\in.txt","r",stdin); const int N=100001; int n,ii=0; _leaf leaf ; int parent ; double p,r,pr; scanf("%d%lf%lf",&n,&p,&r); pr=1+r/100; for(int i=0;i<n;i++) { int k; scanf("%d",&k); if(k==0) { scanf("%d",&leaf[ii].amount); leaf[ii].index=i; ++ii; } else { for(int j=0;j<k;j++) { int x; scanf("%d",&x); parent[x]=i; } } } //compute the level of leaf //compute sales from all retailers double ans=0; for(int i=0;i<ii;i++) { int tmp=leaf[i].index; double pr_tmp=1; while(tmp!=0) { pr_tmp*=pr; tmp=parent[tmp]; } ans+=pr_tmp*leaf[i].amount; } printf("%.1lf",ans*p); }
相关文章推荐
- libdvbpsi源码分析(四)PAT表解析/重建
- PAT配置
- 什么是端口复用动态地址转换(PAT) 介绍配置实例
- MikroTik layer7-protocol
- PAT是如何工作的
- PAT (Advanced Level) Practise 1001-1010
- 数据结构学习与实验指导(一)
- PAT Basic Level 1001-1010解题报告
- 2-06. 数列求和{PAT}
- 1004. 成绩排名 (20){PAT}
- PAT 2-05. 求集合数据的均方差
- PAT 2-06. 数列求和
- PAT 1057 Stack (30)
- PAT(Advanced Level) 1004 Counting Leaves 解题报告
- PAT(Advanced Level) 1020 Tree Traversals 解题报告
- PAT(Advance Level) 1048 Find Coins 解题报告
- PAT(Advance Level) 1007 Maximum Subsequence Sum 解题报告
- PAT 1018的陷阱
- PAT 1006的坑
- PAT_1055 world richest 多键排序