PAT 甲级 1106. Lowest Price in Supply Chain (25)
来源:互联网 发布:php json转数组为null 编辑:程序博客网 时间:2024/06/05 15:26
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. Only the retailers will face the customers. 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 lowest price a customer 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 their ID's are numbered from 0 to N-1, and the root supplier's ID is 0); P, the price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then N lines follow, each describes a distributor or retailer in the following format:
Ki ID[1] ID[2] ... ID[Ki]
where in the i-th line, Ki is the total number of distributors or retailers who receive products from supplier i, and is then followed by the ID's of these distributors or retailers. Kj being 0 means that the j-th member is a retailer. All the numbers in a line are separated by a space.
Output Specification:
For each test case, print in one line the lowest price we can expect from some retailers, accurate up to 4 decimal places, and the number of retailers that sell at the lowest price. There must be one space between the two numbers. It is guaranteed that the all the prices will not exceed 1010.
Sample Input:10 1.80 1.003 2 3 51 91 41 702 6 11 8000Sample Output:
1.8362 2
#include <algorithm>#include <cstdio>#include <iostream>#include <vector>#include <queue>using namespace std;vector<int> v[1000005];int mindepth = 99999999, minnum = 1;void dfs(int index, int depth){if (mindepth < depth) return;if (v[index].size() == 0) {if (mindepth == depth)minnum++;else if (mindepth>depth) {mindepth = depth;minnum = 1;}}for (int i = 0; i < v[index].size(); i++)dfs(v[index][i], depth + 1);}int main() {int n, k, c;double p, r;scanf("%d %lf %lf", &n, &p, &r);for (int i = 0; i < n; i++) {scanf("%d", &k);for (int j = 0; j < k; j++) {scanf("%d", &c);v[i].push_back(c);}}dfs(0,0);printf("%.4f %d", p*pow(1 + r / 100, mindepth), minnum);return 0;}
- 1106. Lowest Price in Supply Chain (25) PAT甲级
- PAT 甲级 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)-PAT甲级真题(dfs,bfs,树的遍历)
- PAT甲级真题及训练集(26)--1106. Lowest Price in Supply Chain (25)
- PAT--1106. Lowest Price in Supply Chain
- 【PAT】1106. Lowest Price in Supply Chain
- 【PAT】1106. Lowest Price in Supply Chain (25)
- PAT 1106. Lowest Price in Supply Chain (25)
- pat 1106. Lowest Price in Supply Chain (25)
- PAT 1106. Lowest Price in Supply Chain (25)
- pat 1106. Lowest Price in Supply Chain (25)
- PAT A 1106. Lowest Price in Supply Chain (25)
- 【PAT】【Advanced Level】1106. Lowest Price in Supply Chain (25)
- Pat(A) 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 分享两个线+标注的SLD样式
- uva11175
- The Stack Is An Implementation Detail, Part One
- 小型超市网上购物系统开发项目总结
- #{}和${}的区别
- PAT 甲级 1106. Lowest Price in Supply Chain (25)
- 树链剖分+线段树 HDU3966 权值在点 模板
- ios开发 Could not signal service com.apple.WebKit.WebContent: 113
- eclipse快捷键整理
- 单例模式
- ionic cordova andoid环境配置
- 运算符重载 编程题#2(Coursera 程序设计与算法 专项课程3 C++程序设计;重载:& operator-)
- PHP实现HTTP断点续传的方法
- 密码输入框显示为文字