1090. Highest 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. 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 highest price we 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 they are numbered from 0 to N-1); P, the price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then the next line contains N numbers, each number Si is the index of the supplier for the i-th member. Sroot for the root supplier is defined to be -1. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print in one line the highest price we can expect from some retailers, accurate up to 2 decimal places, and the number of retailers that sell at the highest price. There must be one space between the two numbers. It is guaranteed that the price will not exceed 1010.

Sample Input:

9 1.80 1.00
1 5 4 4 -1 4 5 3 6

Sample Output:

1.85 2

提交代码

每次只让不为叶结点的节点入队。BFS。

 #include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
map<int,vector<int> > edge;
int main()
{
//freopen("D:\\INPUT.txt","r",stdin);
int n,i,num,core;
double price,r;
scanf("%d %lf %lf",&n,&price,&r);
for(i=;i<n;i++){
scanf("%d",&num);
if(num==-){
core=i;
}
else{
edge[num].push_back(i);
}
}
int last=core,e=core,cur;
queue<int> q;
int maxcount=,count=;
r/=;
if(edge[core].size()){//只让下面还有节点的点入队,不让叶结点入队
q.push(core);
} //cout<<price<<endl; while(!q.empty()){
cur=q.front();
q.pop();
for(i=;i<edge[cur].size();i++){//只让下面还有节点的点入队,不让叶结点入队
if(edge[edge[cur][i]].size()){
q.push(edge[cur][i]);
last=edge[cur][i];
}
else{
count++;//计叶结点数
}
}
//cout<<"cur: "<<cur<<endl;
if(e==cur){
e=last;
price*=+r;
maxcount=count; //cout<<cur<<" "<<e<<" "<<price<<endl; count=;
}
}
printf("%.2lf %d\n",price,maxcount);
return ;
}

最新文章

  1. 使用po模式读取豆瓣读书最受关注的书籍,取出标题、评分、评论、题材 按评分从小到大排序并输出到txt文件中
  2. Linux学习记录
  3. ASP.NET Identity 简介
  4. 桥接模式(Bridge)
  5. redis 内存
  6. C#读写Json
  7. oracle case when 语句
  8. 实用JS大全
  9. linux修改主机名
  10. [Leetcode][Python]31: Next Permutation
  11. BrowserSync使用
  12. 201521123034《Java程序设计》第十一周学习总结
  13. hihoCoder 1596 : Beautiful Sequence
  14. 通过重写request.getParameter方法来解决中文乱码问题。
  15. vue 数组
  16. VC6.0在win 8.1中的安装使用
  17. ORA-06530: 引用未初始化的组合 ;
  18. P3850 [TJOI2007]书架
  19. Dynamics CRM 2011 权限管理
  20. java类中访问属性

热门文章

  1. Service Fabric 注意事项
  2. 移除HTML标签(CharacterUtility)类库
  3. Docker 的优势
  4. meta常用命令
  5. 浅谈UBUNTU
  6. laravel5.2总结--返回值
  7. 屏幕字段不允许直接输入,只能通过SearchHelp(F4)
  8. [USACO08OPEN]农场周围的道路Roads Around The Farm BZOJ 1621 DFS
  9. .net mvc 框架实现后台管理系统 2
  10. hau1021 Fibonacci Again(递归)