1090. Highest Price in Supply Chain (25)
来源:互联网 发布:云计算工程师好干吗 编辑:程序博客网 时间:2024/06/08 04:34
#include<cstdio>#include<queue>#include<vector>using namespace std;#define maxn 100010struct node{ double price; vector<int> child;}tree[maxn];int N,head,cnt=0;double init_price,r,max_price=0;void level_order(int root){ queue<int> qu; qu.push(root); tree[root].price = init_price; while (! qu.empty()) { int front = qu.front(); qu.pop(); if(tree[front].price > max_price) { max_price = tree[front].price; cnt = 1; } else if(tree[front].price == max_price) { cnt++; } for(int i=0; i<tree[front].child.size(); i++) { int child = tree[front].child[i]; tree[child].price = tree[front].price * (1.0 + r/100.0); qu.push(child); } }}int main(){ //读入数据 scanf("%d%lf%lf",&N,&init_price, &r); //读入节点,并构造树 for(int i=0; i<N; i++) { int father; scanf("%d",&father); if(father == -1) { head = i; } else { tree[father].child.push_back(i); } } //层序遍历 level_order(head); //输出 printf("%.2f %d",max_price,cnt); 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)
- 1088. Rational Arithmetic (20)
- Train Problem I (栈的模拟)
- npm安装
- 冒泡排序
- iptable使用笔记
- 1090. Highest Price in Supply Chain (25)
- Python中的新奇玩意
- POSIX(Portable Operating System Interface )信号处理
- 1092. To Buy or Not to Buy (20)
- 1.3props与state
- Windows每月更新补丁离线安装包下载
- 仙人掌相关问题的处理方法(未完待续)
- 1094. The Largest Generation (25)
- Gson的使用