A1079基于本题
读题不能有太强的代入感,要从题目中获取,不是自己想当然.
the number of retailers that sell at the highest price:卖最高价格的零售商数目.(而不是卖最高价格的结点是哪一个)
本题的本质便是通过DFS获取到最大深度以及该深度的结点数.
DFS:
#include<cstdio>
#include<cstdlib>
#include<string.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;
const int maxn=100010;
vector<int> child[100010];
int final_layer=-1,num=0;
void DFS(int root,int layer){
if(child[root].size()==0){
if(layer>final_layer){
final_layer=layer;
num=1;
}else if(layer==final_layer){
num++;
}
return;
}
for(int i=0;i<child[root].size();i++){
DFS(child[root][i],layer+1);
}
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt","r",stdin);
#endif
double p,r;
int root,n;
scanf("%d %lf %lf",&n,&p,&r);
for(int i=0;i<n;i++){
int temp;
scanf("%d",&temp);
if(temp==-1){
root=i;
}else{
child[temp].push_back(i);
}
}
DFS(root,0);
printf("%.2f %d\n",p*pow(1+r*0.01,(double)final_layer),num);
//final_layer可以不强制转换为double型.pow()函数返回值必须是double型,但内部可以是int型.
return 0;
}