1090. Highest Price in Supply Chain (25)
来源:互联网 发布:常任理事国知乎 编辑:程序博客网 时间:2024/05/21 10:21
#include<iostream> #include<queue> #include<vector> #include<algorithm> using namespace std; const int N = 1000010; struct node{ vector<int> child; int level; }node[N]; void levelorder(int root){ queue<int> q; node[root].level = 0; q.push(root); while(!q.empty()){ int p = q.front(); q.pop(); for(int i = 0; i < node[p].child.size(); i++){ int temp = node[p].child[i]; q.push(temp); node[temp].level = node[p].level + 1; } } } int main(){ int n ; double p , r; int root; cin>>n>>p>>r; for(int i = 0; i < n; i++){ int temp; scanf("%d",&temp); if(temp == -1) root = i; else{ node[temp].child.push_back(i); } } if(n == 1){ printf("%.2lf %d",p,n); return 0; } levelorder(root); int num = 0, maxlevel = 0; double maxprice = p; for(int i = 0; i < N; i++){ if(maxlevel < node[i].level) maxlevel = node[i].level; } for(int i = 0; i < N; i++){ if(maxlevel == node[i].level) num++; // 当只有一个点的话num = N,会导致一个1分的点不过 } for(int i = 0; i < maxlevel; i++){ maxprice *=(1.0 + r/100); } printf("%.2lf %d",maxprice,num); return 0; }当只有一个点的话
0 0
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 一次自制腊肉的过程
- BCD转int
- C语言中的指针与数组
- ACM之LeetCode中Add Two Numbers
- 快速掌握前端的HTTP基础(1)
- 1090. Highest Price in Supply Chain (25)
- 数学分析--泰勒定理的故事
- 我的web前端自学之路-心得篇:我为什么要学习web前端?
- [SinGuLaRiTy-1000] High Percision Calculation 高精度算法集锦
- 主席树笔记
- 龟兔赛跑预测
- Java——可变长参数列表
- 中介者模式
- PIL学习随笔