A1090

你离开我真会死。 提交于 2020-02-02 04:10:48

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;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!