pat-a1090. Highest Price in Supply Chain (25)
来源:互联网 发布:什么是编程语言 编辑:程序博客网 时间:2024/06/10 16:03
树这类基础题还是有基础。。应该尽快刷到图弥补不足
#include<cstdio>#include<vector>#include<cmath>#include<map>using namespace std;map<int,vector<int> >tree;int level=0,sum=0;void dfs(int root,int t){int len=tree[root].size();if(len==0){if(level<t){level=t;sum=1;}else if(level==t){sum++;}return;}for(int i=0;i<len;++i) dfs(tree[root][i],t+1);}int main(){int n,temp,root;double m,r;scanf("%d%lf%lf",&n,&m,&r);for(int i=0;i<n;++i){scanf("%d",&temp);if(temp!=-1) tree[temp].push_back(i);else root=i;}dfs(root,0);printf("%.2lf %d\n",m*pow(1+r/100,level),sum);}
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.
Starting from one root supplier, everyone on the chain buys products from one's supplier in a price P and sell or distribute them in a price that is r% higher than P. It is assumed that each member in the supply chain has exactly one supplier except the root supplier, and there is no supply cycle.
Now given a supply chain, you are supposed to tell the highest price we can expect from some retailers.
Input Specification:
Each input file contains one test case. For each case, The first line contains three positive numbers: N (<=105), the total number of the members in the supply chain (and hence they are numbered from 0 to N-1); P, the price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then the next line contains N numbers, each number Si is the index of the supplier for the i-th member. Sroot for the root supplier is defined to be -1. All the numbers in a line are separated by a space.
Output Specification:
For each test case, print in one line the highest price we can expect from some retailers, accurate up to 2 decimal places, and the number of retailers that sell at the highest price. There must be one space between the two numbers. It is guaranteed that the price will not exceed 1010.
Sample Input:9 1.80 1.001 5 4 4 -1 4 5 3 6Sample Output:
1.85 2
- PAT A1090 Highest Price in supply chain
- PAT A1090. Highest Price in Supply Chain (25)
- pat-a1090. Highest Price in Supply Chain (25)
- A1090. Highest Price in Supply Chain (25)
- PAT A1090 highest price of supply chain(25)
- pat 1090 Highest Price in Supply Chain
- PAT 1090. Highest Price in Supply Chain
- PAT 1090 Highest Price in Supply Chain
- 【PAT】1090. Highest Price in Supply Chain
- PAT 1090. Highest Price in Supply Chain (25)
- PAT A 1090. Highest Price in Supply Chain (25)
- PAT 1090. Highest Price in Supply Chain (25)(DFS)
- PAT 1090. Highest Price in Supply Chain (25)
- 【PAT】1090. Highest Price in Supply Chain (25)
- PAT 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25) PAT甲级
- PAT-A-1090. Highest Price in Supply Chain (25)
- PAT 甲级 Highest Price in Supply Chain (25)
- 编译工具
- 回溯法在排列组合问题中的应用
- mkv210_image.c
- HAProxy+Keepalived配置邮件报警,会话保存机制和TCP端口范围(三)
- scoket客户端扫描电脑可用端口小demo
- pat-a1090. Highest Price in Supply Chain (25)
- Sping框架概述
- 数据库系统常用的存取方法
- sed、awk
- ireport + jasperreport报表使用 Parameters传递 where或 group by异常解决
- 六个通用寄存器的特定用途
- Linux的第二天(安装Eclipse和FFmpeg)
- POJ 3249 Test for Job
- 没GPU也能玩梵高作画:Ubuntu tensorflow CPU版