PAT
来源:互联网 发布:mac如何截取长图 编辑:程序博客网 时间:2024/06/16 16:41
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
给定要求:
1.n个节点以及之间的关系
要求:
1.根节点要叶子节点之间最远距离
解:
1.dfs遍历该树
#include<cstdio>#include<cmath>#include<vector>using namespace std;int n, root, cnt;double r, p, maxP=-1;vector<int> node[100001];void dfs(int v, int d){if(node[v].size() == 0){double curP = p * pow((r+100.0)/100.0, d);if(curP == maxP){cnt++;}else if(curP > maxP){cnt = 1;maxP = curP;}return ;}else{for(int i = 0; i < node[v].size(); i++){dfs(node[v][i], d+1);}}}int main(){scanf("%d%lf%lf", &n, &p, &r);cnt = 0;int t;for(int i = 0; i < n; i++){scanf("%d", &t);if(t == -1){root = i;continue;}else{node[t].push_back(i);}}dfs(root,0);printf("%.2f %d\n",maxP, cnt);return 0;}
- pat
- 【PAT】
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- pat
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- 属性getter和setter
- 2017双十一阿里技术汇总
- C语言实验——整数位
- Django-restframework34 Testing(测试)
- HBase 常用Shell命令
- PAT
- 08 C++11中的variadic template、auto和for基本用法(学自Boolean)
- 由于对必需的库\jdk1.7.0\jre\lib\rt.jar 具有一定的访问限制问题 解决方法
- mysql根据标签查询文章相似度
- Android framework学习笔记 -- Google tracing的研究
- GC原理及优化
- 2017 CCPC 哈尔滨 M ( hdu 6242) Geometry Problem (随机化 + 三角形外心)
- 1022. D进制的A+B (20)
- Test