#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
int n;
double p,r;
int mindepth=1000000000;
//最好带个零防止不够
vector<int> v[100009];
//最小个数信息注意条件重置
int minnum=1;
void dfs(int index,int depth)
{ //递归边界避免出门即死如果现在的mindepth<depth则没有必要去弄了
if(mindepth<depth)
return;
//零售店 到根节点才能赋值mindepth
if(v[index].size()==0)
{ if(mindepth>depth)
{
mindepth=depth;
//条件重置
minnum=1;
}
else if(mindepth==depth)
minnum++;
}
for(int i=0;i<v[index].size();i++)
{
dfs(v[index][i],depth+1);
}
}
int main()
{ //double 与longdouble的区别
//%f %lf 意义分别是什么不清楚(注意)
scanf("%d",&n);
scanf("%lf",&p);
scanf("%lf",&r);
int q,h;
for(int i=0;i<n;i++)
{
cin>>q;
//截断输入一行分两次要
//i,j,要分开,是谁进是第一个坐标还是第二个坐标想错了
for(int j=0;j<q;j++)
{
cin>>h;
v[i].push_back(h);
}
}
dfs(0,0);
//4 decimal places and the number of retailers that sell at the lowest pric1.8362 2
printf("%.4f %d",p*pow(1+r/100,mindepth),minnum);
return 0;
}
总结:
1. 这里dfs用了层号与深度作为传入参数
2.关于输入double型变量必须用%lf 与float型要区分开不然会出错
1.C语言中printf输出baifloat和double都可以用%f,而dudouble型数zhi据还可以用%lf。2.scanf当中若是对dao双精度的变量赋值是zhuan必须是%后跟lf,而printf当中可以用%f也可以用%lf没有限制。
3.多层嵌套for循环 计数变量要选用不同值,并且想清楚到底是要对那个计数变量操作
4.pushbcak与resize不能混用
5.根节点这里天然用无作为了终止条件
6.截断输入信息 一行中截断第一个与后面的直接用第一个作为信息,边出入边处理
7.注意条件重置这里每找到一个更深的结点就要重置与他相等的结点个数为一
英语:
问题
1.scanf不清晰
2.cmath头文件的函数快忘了
3.递归参数的选取不清晰