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. VMWare虚拟机无法打开内核设备"\\.\Global\vmx86"的解决方法

    cmd执行: 1.net start vmci 2.net start vmx86 3.net start VMnetuserif

  2. CodeSmith链接MySQL

    环境:Win7 x64 旗舰版 CodeSmith Generator Professional 6.5.0 MySQL 5.6.17 x64 在CodeSmith中按一般步骤创建数据库连接 Data ...

  3. vuejs API总结

    vuejs总结: vm指new Vue获取的实例 (1)当dom标签里的值和data里的值绑定后,更改data对应的值可以实时更新标签里的值: 但后续添加的值是无效的(绑定失败). (2)将可以将对象 ...

  4. 区块链中的密码学(-)区块链中运用最广的散列算法-SHA256算法分析与实现

    在很多技术人员的眼中,区块链并不是一种新的技术,而是过去很多年计算机技术的组合运用.而在这个方方面面技术的运用上,基于密码学的加密算法可以说是区块链各种特点得以表现的根本,一旦目前使用的加密算法被证实 ...

  5. [Oracle入门级]知识概况

    oracle各个版本间的主要技术更新 oracle 增加数据库创建和存储对象 oracle 8i 整体性能提升 oracle9i 实施应用集群 oracle 10g 支持网格计算 oracle 11g ...

  6. Node JS后端项目开发与生产环境总结

    原文地址:Node JS后端项目开发与生产环境总结 Node JS常用后端框架有express.koa.sails.国产框架有个egg js,已经在cnode投入生产了,还有个think js,类似t ...

  7. C++ 标准库智能指针

    整理一下c++中shared_ptr,weak_ptr,unique_ptr三种指针的使用案例和注意事项,让程序资源更加案例,在标准库中,需要包含<memory>,在boost库中, 一. ...

  8. Problem Arrangement ZOJ - 3777(状压dp + 期望)

    ZOJ - 3777 就是一个入门状压dp期望 dp[i][j] 当前状态为i,分数为j时的情况数然后看代码 有注释 #include <iostream> #include <cs ...

  9. git push fatal: HttpRequestException encountered

    原因: github禁用了TLS1.0/1.1协议 截至2018年2月22日,GitHub禁用了对弱加密的支持,这意味着许多用户会突然发现自己无法使用Git for Windows进行身份验证(影响版 ...

  10. python爬取抖音APP视频教程

    本文讲述爬取抖音APP视频数据(本文未完,后面还有很多地方优化总结) 公众号回复:抖音 即可获取源码 1.APP抓包教程,需要用到fiddler fiddler配置和使用查看>>王者荣耀盒 ...