PAT A1090 highest price of supply chain(25)
来源:互联网 发布:各种软件神器手机软件 编辑:程序博客网 时间:2024/06/06 05:06
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int n,maxlayer=1;
double rootprice,rttsum=0,r;
struct node{
double price;//layer function
int layer;
int num;
vector<int> receive;
}node[100010];
void BFS(int root){
queue<int> q;
node[root].price=rootprice;
node[root].layer=1;
q.push(root);
while(!q.empty()){
int front=q.front();
q.pop();
for(int i=0;i<node[front].receive.size();i++){
node[node[front].receive[i]].layer=node[front].layer+1;
//node[node[front].receive[i]].price=node[front].price*(1+(r/100));
if(node[node[front].receive[i]].layer>maxlayer) maxlayer=node[node[front].receive[i]].layer;
q.push(node[front].receive[i]);
}
}
int num=0;
double maxprice;
maxprice=rootprice*pow(1+r,maxlayer-1);
for(int i=0;i<n;i++){
if(node[i].layer==maxlayer){
num++;
}
}
printf("%.2f %d\n",maxprice,num);
}
int main(){
scanf("%d%lf%lf",&n,&rootprice,&r);
r/=100;
int i,k,pnum,j,id,root;
for(i=0;i<n;i++){
scanf("%d",&k);
if(k!=-1) node[k].receive.push_back(i);
else root=i;
}
BFS(root);
system("pause");
return 0;
}
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int n,maxlayer=1;
double rootprice,rttsum=0,r;
struct node{
double price;//layer function
int layer;
int num;
vector<int> receive;
}node[100010];
void BFS(int root){
queue<int> q;
node[root].price=rootprice;
node[root].layer=1;
q.push(root);
while(!q.empty()){
int front=q.front();
q.pop();
for(int i=0;i<node[front].receive.size();i++){
node[node[front].receive[i]].layer=node[front].layer+1;
//node[node[front].receive[i]].price=node[front].price*(1+(r/100));
if(node[node[front].receive[i]].layer>maxlayer) maxlayer=node[node[front].receive[i]].layer;
q.push(node[front].receive[i]);
}
}
int num=0;
double maxprice;
maxprice=rootprice*pow(1+r,maxlayer-1);
for(int i=0;i<n;i++){
if(node[i].layer==maxlayer){
num++;
}
}
printf("%.2f %d\n",maxprice,num);
}
int main(){
scanf("%d%lf%lf",&n,&rootprice,&r);
r/=100;
int i,k,pnum,j,id,root;
for(i=0;i<n;i++){
scanf("%d",&k);
if(k!=-1) node[k].receive.push_back(i);
else root=i;
}
BFS(root);
system("pause");
return 0;
}
0 0
- PAT A1090 highest price of supply chain(25)
- PAT A1090 Highest Price in supply chain
- PAT A1090. Highest Price in Supply Chain (25)
- pat-a1090. Highest Price in Supply Chain (25)
- A1090. Highest Price in Supply Chain (25)
- PAT 1090. Highest Price in Supply Chain (25)(DFS)
- PAT 1090. Highest Price in Supply Chain (25)
- PAT A 1090. Highest Price in Supply Chain (25)
- PAT 1090. Highest Price in Supply Chain (25)
- 【PAT】1090. Highest Price in Supply Chain (25)
- PAT 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25) PAT甲级
- PAT-A-1090. Highest Price in Supply Chain (25)
- PAT 甲级 Highest Price in Supply Chain (25)
- Pat(A) 1090. Highest Price in Supply Chain (25)
- 准备PAT之Highest Price in Supply Chain (25)
- 【PAT】【Advanced Level】1090. Highest Price in Supply Chain (25)
- 【PAT 1003 Highest Price in Supply Chain (25)】 & dfs
- UVA 10820 Send a Table (欧拉函数打表)
- 1. java对象 引用
- 解决win10用户权限导致软件启动异常问题
- 一步一步走向自定义控件
- Java —— 静态变量的声明和初始化
- PAT A1090 highest price of supply chain(25)
- 17.3.02 Git学习笔记
- iOS内存泄露检测工具MLeaksFinder
- 九度OJ 题目1023:EXCEL排序
- 线程池的最优大小
- mysql 带参数的存储过程插入百万条记录示例
- thread.join()的实例
- quartz定时持久化改造
- linux cut用法