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. 人工智能热门图书(深度学习、TensorFlow)免费送!

    欢迎访问网易云社区,了解更多网易技术产品运营经验. 这个双十一,人工智能市场火爆,从智能音箱到智能分拣机器人,人工智能已逐渐渗透到我们的生活的方方面面.网易云社区联合博文视点为大家带来人工智能热门图书 ...

  2. java 学习第零篇JDK安装和记事本编辑JAVA

    用记事本来编写java 首先你要安装JDK. 第一步下载JDK. 这步不多BB. 第二部安装JDK. 你要么改安装地址或者默认. 也不多BB. 第三步配置环境变量 WIN10为例: 此电脑 右键  属 ...

  3. (转)Haar-like矩形遍历检测窗口演示Matlab源代码

    from:http://blog.sina.com.cn/s/blog_736aa0540101kzqb.html clc; clear; close all; % Haar-like特征矩形计算 b ...

  4. day-15递归与函数

    生成器send方法 send的工作原理 1.send发生信息给当前停止的yield 2.再去调用__next__()方法,生成器接着往下指向,返回下一个yield值并停止 # 案例: persons ...

  5. 51nod1445(最短路)

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1445 题意: 中文题诶~ 思路: 可以将每种颜色看作一个节点 ...

  6. oracle多用户并发及事务处理

    多用户并发访问 事务:作用于某些数据的一个不可分割的操作   锁:写锁.互斥锁(仅能被一个进程使用)      读锁.共享锁(可被多个进程使用)   更新丢失 脏读 不可重复读 幻影读   隔离级别: ...

  7. javascript小菜单—demo

    <!DOCTYPE html><html><head> <title></title></head><body>&l ...

  8. atcoder 2643 切比雪夫最小生成树

    There are N towns on a plane. The i-th town is located at the coordinates (xi,yi). There may be more ...

  9. 教主的花园 dp

    题目描述 教主有着一个环形的花园,他想在花园周围均匀地种上n棵树,但是教主花园的土壤很特别,每个位置适合种的树都不一样,一些树可能会因为不适合这个位置的土壤而损失观赏价值. 教主最喜欢333种树,这3 ...

  10. 存储过程中的select into from是干什么的

    select into  赋值: select 0 into @starttimeselect @starttime from DUAL into后边应该还有个变量名,into前面也还要带上筛选字段, ...