1106 Lowest Price in Supply Chain (25 分)
作者:互联网
经销商问题,与前几题类似;
坑点如下
1,很大的数的表示方法
const double INF=1e12;
整体代码如下
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
const int maxn=100010;
const double INF=1e12;
int n;
double p,r;
struct Node{
vector<int>child;
double price;
}node[maxn];
double lp=INF;
int lnum=0;
int main(){
scanf("%d%lf%lf",&n,&p,&r);
int num;
for(int i=0;i<n;i++){
scanf("%d",&num);
if(num!=0){
int child;
for(int l=0;l<num;l++){
scanf("%d",&child);
node[i].child.push_back(child);
}
}
}
node[0].price=p;
queue<int>Q;
Q.push(0);
while(!Q.empty()){
int q=Q.front();
Q.pop();
if(node[q].child.size()!=0){
for(int i=0;i<node[q].child.size();i++){
node[node[q].child[i]].price=node[q].price*(1+r/100);
Q.push(node[q].child[i]);
}
}
else
{ if(node[q].price<lp){
lp=node[q].price;
lnum=1;
}
else if(node[q].price==lp){
lnum++;
}
}
}
printf("%.4f %d",lp,lnum);
}
标签:Lowest,25,node,Chain,int,double,price,child,include 来源: https://blog.csdn.net/pikachupikapika/article/details/119462460