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. Repeater控件的分隔线

    在Repeater控件中,很容易实现在行与行之间使用分隔线.因为此控件有内置的SeparatorTemplate模版.举个例子吧: 运行时,可以看到效果: 说句实在的话,Insus.NET做一条水平线 ...

  2. Hibernate常见异常总结

    系统配置 1.没有查找到src目录下的hibernate.cfg.xml Exception in thread "main" org.hibernate.HibernateExc ...

  3. luogu1900 自我数

    分享一个非正解的做法 本题解内存最低(\(\le1\rm MiB\)) 但是不开O2会tle 思路:每个数字仅会更新出1个新的数字,而且这个新数字比旧数字最多也就大70多.所以这里还是利用" ...

  4. 用rc.local工具开机自启动

    对于一些程序来说,无法直接开机自启动.那么我们可以利用开机自启动来执行一些命令,达到开机自启动的效果!!! 下面用tomcat来举个例子 tomcat启动的命令一般是./startup.sh 那么我们 ...

  5. DataSet强类型、TableAdapter的使用

    简答使用可以看https://www.cnblogs.com/namejr/p/10411920.html中的"先来简单介绍dataset和datatable" DataSet强类 ...

  6. Linux中切换前后台命令:ctrl+z,bg,fg,jobs

    一.运行某些服务的时候,我希望切换到后台运行: 两种方法: 1.可以在运行的时候,在启动服务命令的最后面加一个字符&,例如 ./serviceStart & 2.在服务启动后,按ctr ...

  7. ssh免密登录linux服务器

    Ssh免密登录 sshd服务 sshd简介: SSH 密钥为登录 Linux 服务器提供了更好且安全的机制.运行 ssh-keygen 后,将会生成公私密钥对.你可以将公钥放置到任意服务器,从持有私钥 ...

  8. java web 简单的权限管理

    spring ,springMvc ,mybatis 简单权限管理 其实只需要3张表..admin_group  ,function,group 表

  9. [USACO18JAN]Cow at Large G(树形DP)

    P4186 [USACO18JAN]Cow at Large G(树形DP) Luogu4186 设dp[i]表示i点需要放多少个农民.则有 \(if(near[i]-dep[i]<=dep[i ...

  10. Diophantus of Alexandria

    Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first ma ...