1090 Higest Price in Supply Chain
来源:互联网 发布:云计算怎么实现 编辑:程序博客网 时间:2024/06/06 17:21
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
解题思路:根据输入构建一棵树,然后找一下树的最大深度
#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>[n]; 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;}
- 1090 Higest Price in Supply Chain
- pat 1090 Highest Price in Supply Chain
- PAT 1090 Highest Price in Supply Chain
- Highest Price in Supply Chain
- Pat(Advanced Level)Practice--1090(Highest Price in Supply Chain)
- PAT A 1090 Highest Price in Supply Chain 深搜
- 1090. Highest Price in Supply Chain
- PAT 1090. Highest Price in Supply Chain
- 1090. Highest Price in Supply Chain (25)
- 1090.Highest Price in Supply Chain
- 1090. Highest Price in Supply Chain (25)
- pat1090 Highest Price in Supply Chain
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain
- PAT A1090 Highest Price in supply chain
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 深入理解JVM之垃圾回收详解
- 第一天:代码入门、HTML语法基础及文档类标签
- ios静态库与动态库的区别
- jq与JS点击显示隐藏二级菜单的几种方法
- 白话Spring(基础篇)---helloworld
- 1090 Higest Price in Supply Chain
- 学习android service记录
- Linux 初始化之 Systemd机制简介
- Swift 笔记(四)
- UML图与机房收费系统实例
- 使用Memory Analyzer tool(MAT)分析内存泄漏(二)
- java.lang.ThreadLocal实现原理和源码分析
- 四叉树空间索引原理及其实现
- ios 开发中 动态库 与静态库的区别