A1106. Lowest Price in Supply Chain (25)
来源:互联网 发布:mvc php路由文件加载 编辑:程序博客网 时间:2024/06/06 02:12
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
注意,num的类型如果是double,不能++,++不报错但是结果一直是0,手贱定义错位置了,应该改成int,卡了好久。
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<vector>#include<cmath>using namespace std;const int maxn=100010;const double INF=1e12;vector<int> child[maxn];double ans=0,minans=INF;int num=0;int n;double p,r;void DFS(int root,int depth){if(child[root].size()==0){ans=p*pow(1+r,depth);if(ans<minans){minans=ans;num=1;//重发现最小的位置,个数置1}else if(ans==minans)num++;//如果最小的相同,说明又有一个同样层数的叶子节点。return;}else{for(int i=0;i<child[root].size();i++){DFS(child[root][i],depth+1);}}}int main(){freopen("data.in","r",stdin);scanf("%d %lf %lf",&n,&p,&r);r=r/100;for(int i=0;i<n;i++){int k,temp;scanf("%d",&k);for(int j=0;j<k;j++){scanf("%d",&temp);child[i].push_back(temp);}}DFS(0,0);printf("%.4lf %d",minans,num);return 0;}
- A1106. Lowest Price in Supply Chain (25)
- PAT A1106. Lowest Price in Supply Chain (25)
- pat-a1106. 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)
- linux(ubuntu)编译linux内核提示"mkimage" command not found
- Tomcat的性能与最大并发数
- R语言(转载)之par()函数
- Linux驱动手动绑定和解绑定
- HashMap多线程下发生死循环的原因
- A1106. Lowest Price in Supply Chain (25)
- springboot data rest 4
- 加密ASP为DLL的详细步骤给点RMB不多是个心意尊重脑力劳动者的付出
- c++实现日志系统(含源码)
- Spring 数据访问那些事儿(二)Spring + JdbcTemplate
- java动态代理和cglib动态代理
- 分冶-二分查找
- ubuntu 改时区
- Java7:int i=0b010101;