1106. Lowest Price in Supply Chain (25)
来源:互联网 发布:奶瓶蹭网软件 编辑:程序博客网 时间:2024/06/06 23:55
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
与1090题类似,这里求的是最小售价。只要求出供应链中最短的链的长度就可以得到答案。这里用dfs实现。
代码:
#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <vector>#include <cmath>using namespace std;int n;double p,r;vector<vector<int> >chain;int Min=1<<30,count=0;void dfs(int cur,int level){if(chain[cur].size()==0){if(level<Min){Min=level;count=1;}else if(level==Min){count++;}return;}for(int i=0;i<chain[cur].size();i++){dfs(chain[cur][i],level+1);}}int main(){cin>>n>>p>>r;chain.resize(n);for(int i=0;i<n;i++){int k;cin>>k;for(int j=0;j<k;j++){int rt;cin>>rt;chain[i].push_back(rt);}}dfs(0,0);double res=p*pow((1+r/100),Min);printf("%.4f %d",res,count);}
- 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)
- 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)
- 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)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain(25)
- 1106. Lowest Price in Supply Chain (25)
- Eclipse 使用C++类库:pthread和openssl
- eclipse中不能找到dubbo.xsd解决方法
- 最常见功能的封装(功能之间的组装)
- hdu 1213 并查集
- linux-vi编辑器的使用
- 1106. Lowest Price in Supply Chain (25)
- iOS 面试题(3)
- 常见的页面调度算法
- 1.策略模式(Strategy)
- 九度oj--1001和1048
- glide完整教程
- Java Remote Method Invocation(Java远程方法调用)-- Java分布式计算白皮书
- Android百度地图默认位置中心点设置
- iOS开发中三种简单的动画设置