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 ;
}

pat1090. Highest Price in Supply Chain (25)的更多相关文章

  1. PAT1090:Highest Price in Supply Chain

    1090. Highest Price in Supply Chain (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 C ...

  2. [建树(非二叉树)] 1090. Highest Price in Supply Chain (25)

    1090. Highest Price in Supply Chain (25) A supply chain is a network of retailers(零售商), distributors ...

  3. 1090. Highest Price in Supply Chain (25) -计层的BFS改进

    题目如下: A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyon ...

  4. 1090. Highest Price in Supply Chain (25)

    时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...

  5. 1090 Highest Price in Supply Chain (25)(25 分)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...

  6. PAT Advanced 1090 Highest Price in Supply Chain (25) [树的遍历]

    题目 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)–everyone inv ...

  7. PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)

    简单dfs. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  8. 1090. Highest Price in Supply Chain (25)-dfs求层数

    给出一棵树,在树根出货物的价格为p,然后每往下一层,价格增加r%,求所有叶子节点中的最高价格,以及该层叶子结点个数. #include <iostream> #include <cs ...

  9. Highest Price in Supply Chain (25)(DFS)(PAT甲级)

    #include<bits/stdc++.h>using namespace std;int fa;int degree[100007];vector<int>v[100007 ...

随机推荐

  1. WndProc和hook区别

    1)WndProc函数作用:主要在程序中拦截并处理系统消息和自定义消息 比如:windows程序会产生很多消息,比如你单击鼠标,移动窗口都会产生消息.这个函数就是默认的消息处理函数.你可以重载这个函数 ...

  2. FlowLayoutPanel控件控制里面子控件换行

    // 摘要: // 设置值,该值表示的流中断设置 System.Windows.Forms.FlowLayoutPanel 控件. // // 参数: // control: // 子控件. // / ...

  3. vs code进行c/c++开发

    vs code是微软公司开发的跨平台编辑器,丰富的插件功能可以满足各种编程语言的编码,编译和调试.由于vs code本身只是一个编辑器,所以你需要准备编译工具链.本文针对的是windows系统,我这里 ...

  4. R-CNN

    标题:<Rich feature hierarchies for accurate object detection and semantic segmentation> 时间:2014 ...

  5. ubuntu - 官方简体中文wiki,有你想要的ubuntu的一切

    ubuntu官方简体中文wiki:http://wiki.ubuntu.org.cn/%E9%A6%96%E9%A1%B5

  6. 2019.2.14 考试T1 FFT

    \(\color{#0066ff}{ 题目描述 }\) 衡水二中的机房里经常有人莫名其妙地犇雷,leizi很生气,决定要找出那个犇雷的人 机房有n个人,每个人都认为机房里有两个人可能会犇雷,其中第i个 ...

  7. iOS开发小工具

    基本上在Mac Appstore里面都有,很多是免费的.因为某种原因要重装Mac系统(这么多年来首次重装Mac系统),特意整理了下备忘. 1.AppIcon: 可以瞬间把图片转换为应用所需要的Icon ...

  8. springcloud系列四 搭建服务模块重点讲解

    首先这个服务地址:一定不要写错,是自己注册中心开启的地址 如果注意到这些了,可以简单的进行操作,也可以不需要mybatis与数据库连接,在controller里直接返回相应的数据可以了,不用这么幸苦的 ...

  9. 网站后台登录asp 提示错误号:-2147467259

    方法/步骤   1 asp 提示错误号:-2147467259 提示:[] 错误号:-2147467259 错误描述:操作必须使用一个可更新的查询. SQL错误 解决方法  把data文件夹的权限改下 ...

  10. Python字符串拼接、格式化输出、深浅复制

    1.Python字符串拼接:方法挺多.挺好用的.灵活使用可使代码简洁.可读性好. #1.用4种方法,将列表li = ['I','python','like'], #里面的单词拼成: I**like** ...