A1090

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值