1090 Higest Price in Supply Chain
2016-02-27 15:18
567 查看
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.00
1 5 4 4 -1 4 5 3 6
Sample Output:
1.85 2
解题思路:根据输入构建一棵树,然后找一下树的最大深度
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.00
1 5 4 4 -1 4 5 3 6
Sample Output:
1.85 2
解题思路:根据输入构建一棵树,然后找一下树的最大深度
#include<iostream> #include<vector> #include<stdio.h> #include<math.h> using namespace std; int main(){ int n; double price; double rate; for (; scanf("%d%lf%lf", &n, &price, &rate) != EOF;){ vector<int> *vec = new vector<int> ; int root; for (int i = 0; i < n; i++){ int temp; scanf("%d", &temp); if (temp != -1){ vec[temp].push_back(i); } else{ root = i; } } int level = 0; int count = 1; vector<int>haha; haha.push_back(root); while (count != n){ vector<int>temp; for (int i = 0; i < haha.size(); i++){ for (int j = 0; j < vec[haha[i]].size(); j++){ temp.push_back(vec[haha[i]][j]); count++; } } haha = vector<int>(temp); level++; } printf("%.2lf %d\n", price*pow(rate / 100.0 + 1.0, level*1.0), haha.size()); } return 0; }
相关文章推荐
- 102.Daikon Forge基础使用label、button、sprite、textureAtlas、font
- UVA 10976(p183)----Fractions Again?!
- VS2012 error C2664: “std::make_pair”:无法将左值绑定到右值引用
- 101.Daikon Forge插件介绍和安装
- 格式化数据#8: AIE实验室交流群推荐的相关书籍(附豆瓣链接和ISBN)
- hdu 1151 Air Raid
- DNS IP DOMAIN 详解
- 解决dubbox-demo-provider.xml报错的问题:提示Failed to read schema document
- 【leetcode】【11】Container With Most Water
- 如何解决Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386]
- leetcode 11.Container With Most Water
- 70. Climbing Stairs
- 常见xml的属性大全 转自:http://wenku.baidu.com/link?url=5IqajvhRVAlO7Fr1Ee_IP1rxbwEQU3e6RM5Szde_egqZFf0rma4ZeN
- 利用inotifywait监控主机文件和目录
- WM_PAINT 与 WM_ERASEBKGND(三种情况,比较清楚)
- 窗口绘制有关的消息整理 WM_PAINT, WM_NCPAINT, WM_ERASEBKGND
- WM_PAINT与WM_ERASEBKGND
- 关于WM_ERASEBKGND和WM_PAINT的深刻理解
- TWinControl.WMNCPaint对非客户的绘制
- 2.2 Markov Chain