PAT A1079 tota sales of supply chain (25)
来源:互联网 发布:sql for循环 编辑:程序博客网 时间:2024/04/25 14:10
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int n;
double rootprice,rttsum=0,r;
struct node{
double price;//layer function
int layer;
int num;
vector<int> receive;
}node[100010];
void BFS(){
queue<int> q;
int root=0;
node[0].price=rootprice;
node[0].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));
q.push(node[front].receive[i]);
}
}
for(int i=0;i<n;i++){
if(node[i].receive.size()==0){
rttsum+=(node[i].num*node[i].price);
}
}
printf("%.1f\n",rttsum);
}
int main(){
scanf("%d%lf%lf",&n,&rootprice,&r);
int i,k,pnum,j,id;
for(i=0;i<n;i++){
scanf("%d",&k);
if(k!=0){
for(j=0;j<k;j++){
scanf("%d",&id);
node[i].receive.push_back(id);
}
}
else{
scanf("%d",&pnum);
node[i].num=pnum;
}
}
BFS();
system("pause");
return 0;
}
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int n;
double rootprice,rttsum=0,r;
struct node{
double price;//layer function
int layer;
int num;
vector<int> receive;
}node[100010];
void BFS(){
queue<int> q;
int root=0;
node[0].price=rootprice;
node[0].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));
q.push(node[front].receive[i]);
}
}
for(int i=0;i<n;i++){
if(node[i].receive.size()==0){
rttsum+=(node[i].num*node[i].price);
}
}
printf("%.1f\n",rttsum);
}
int main(){
scanf("%d%lf%lf",&n,&rootprice,&r);
int i,k,pnum,j,id;
for(i=0;i<n;i++){
scanf("%d",&k);
if(k!=0){
for(j=0;j<k;j++){
scanf("%d",&id);
node[i].receive.push_back(id);
}
}
else{
scanf("%d",&pnum);
node[i].num=pnum;
}
}
BFS();
system("pause");
return 0;
}
0 0
- PAT A1079 tota sales of supply chain (25)
- PAT A1079. Total Sales of Supply Chain (25)
- A1079. Total Sales of Supply Chain (25)
- PAT 1079. Total Sales of Supply Chain (25)
- PAT (Advanced) 1079. Total Sales of Supply Chain (25)
- PAT Advanced Level 1079. Total Sales of Supply Chain (25)
- PAT A 1079. Total Sales of Supply Chain (25)
- PAT 1079. Total Sales of Supply Chain (25)
- PAT 1079. Total Sales of Supply Chain (25)
- PAT 1079. Total Sales of Supply Chain (25)
- 【PAT】1079. Total Sales of Supply Chain (25)
- PAT 1014Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)PAT甲级
- PAT甲级练习1079. Total Sales of Supply Chain (25)
- PAT 1079-Total Sales of Supply Chain (25)
- PAT-A-1079. Total Sales of Supply Chain (25)
- 【PAT甲级】1079. Total Sales of Supply Chain (25)
- 【PAT】【Advanced Level】1079. Total Sales of Supply Chain (25)
- <HDU 2072> 单词数
- 点击事件(v-on:click)
- .net 移动api开发基本教程
- Android ListView 几个重要属性
- 【ORACLE】ORA-00054 资源正忙,要求指定 NOWAIT
- PAT A1079 tota sales of supply chain (25)
- java 课堂笔记 第一章java概述
- 计算机英语
- 扩展KMP的模版
- Android 源码内嵌 jar和so文件
- 安装NCCL问题:nvcc fatal : Value 'gnu++0x' is not defined for option 'std'
- js构造函数
- Bootstrap学习-CSS样式
- 元素的隐藏和显示(v-show指令)