PAT A1106. Lowest Price in Supply Chain (25)
来源:互联网 发布:约翰施特劳斯乐团 知乎 编辑:程序博客网 时间:2024/05/16 19:40
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 <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <stack>#include <queue>#include <vector>using namespace std;const int Max = 100001;const int MAX = 0x3fffffff;int n;double p,r;double sum=0;struct Sale{int data;vector<int> child;int depth;}S[Max];queue<int>Q;int Mdep=MAX,Mm=0;void DFS(int root,int dep){if(S[root].child.size()==0){S[root].depth=dep;if(S[root].depth<Mdep){Mdep=S[root].depth;Mm=1;}else if (S[root].depth==Mdep){Mm++;}return ;}for(int i = 0; i<S[root].child.size();i++){DFS(S[root].child[i],dep+1);}return ;}int main(){scanf("%d%lf%lf",&n,&p,&r);r/=100;int temp,ans,root;for(int i=0;i<n;i++){scanf("%d",&temp);S[i].depth=0;for(int j=0;j<temp;j++){scanf("%d",&ans);S[i].child.push_back(ans);}}DFS(0,0); printf("%.4f %d",p*pow(1+r,Mdep),Mm);system("pause");return 0;}
- PAT A1106. Lowest Price in Supply Chain (25)
- pat-a1106. Lowest Price in Supply Chain (25)
- A1106. 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
- 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)
- 1106. Lowest Price in Supply Chain (25) PAT甲级
- 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)
- PAT 甲级 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 【数据结构与算法】B+ tree
- webstorm网页开发调试工具:JetBrains IDE Support Chrome插件下载地址及怎么用?
- oracle数据库还原与备份
- linux之七天总结
- CREELINKS平台_处理器CeAd资源使用说明(CeAd的配置与使用)
- PAT A1106. Lowest Price in Supply Chain (25)
- 260. Single Number III
- 传承开放&&分享的码农精神,个人技术博客上线啦啦啦
- Hello World
- 51Nod-1785-数据流中的算法
- java(2)
- Xcode常用快捷键
- /include/linux/usb.h
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags 贪心、字符串处理