PAT (Advanced Level) Practise 1106 Lowest Price in Supply Chain(25)
2017-06-30 13:33
393 查看
1106. Lowest Price in Supply Chain (25)
时间限制200 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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.00 3 2 3 5 1 9 1 4 1 7 0 2 6 1 1 8 0 0 0
Sample Output:
1.8362 2
题意:有n个人,一件货物在供应商的初始价格为p,货物讲过经销商给零售商,最后卖给顾客。货物每进过一次传递价格提高r%,问顾客得到这件物品需要花费的最少的钱,可以从几个零售商用最少的钱获得这件物品
解题思路:构建一棵树,找到层数最小的叶子节点即可
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <cmath> #include <map> #include <set> #include <stack> #include <queue> #include <vector> #include <bitset> using namespace std; #define LL long long const int INF = 0x3f3f3f3f; int vis[100009],n; int level[100009],s[100009],nt[100009],e[100009]; double r,p; void bfs() { queue<int>q; q.push(0); level[0]=1; while(!q.empty()) { int pre=q.front(); q.pop(); for(int i=s[pre];~i;i=nt[i]) { int ee=e[i]; level[ee]=level[pre]+1; q.push(ee); } } } int main() { while(~scanf("%d%lf%lf",&n,&p,&r)) { r=r/100+1; int k,a,cnt=1; memset(s,-1,sizeof s); memset(vis,0,sizeof vis); for(int i=0;i<n;i++) { scanf("%d",&k); if(!k) vis[i]=1; for(int j=1;j<=k;j++) { scanf("%d",&a); nt[cnt]=s[i],s[i]=cnt,e[cnt++]=a; } } bfs(); int mi=INF,sum=1; for(int i=0;i<n;i++) { if(vis[i]) { if(level[i]<mi) mi=level[i]; else if(level[i]==mi) sum++; } } for(int i=1;i<mi;i++) p*=r; printf("%.4lf %d\n",p,sum); } return 0; }
相关文章推荐
- PAT (Advanced Level) Practise 1106 Lowest Price in Supply Chain (25)
- PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)
- 【PAT】【Advanced Level】1106. Lowest Price in Supply Chain (25)
- PAT-PAT (Advanced Level) Practise Highest Price in Supply Chain(25) 【三星级】
- PAT (Advanced Level) Practise 1090 Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)【树】——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1090 Highest Price in Supply Chain (25)
- pat 1106. Lowest Price in Supply Chain (25)
- Pat(A) 1106. Lowest Price in Supply Chain (25)
- PAT甲级真题及训练集(26)--1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25) PAT甲级
- PAT甲题题解-1106. Lowest Price in Supply Chain (25)-(dfs计算树的最小层数)
- 【PAT】1106. Lowest Price in Supply Chain (25)
- PAT_A 1106. Lowest Price in Supply Chain (25)
- PAT (Advanced Level) 1090. Highest 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甲级真题(dfs,bfs,树的遍历)
- 【PAT】【Advanced Level】1090. Highest Price in Supply Chain (25)