1090 Highest Price in Supply Chain

1090 Highest Price in Supply Chain**发现一个很有意思的现象,用pow得出的数,%.2f会自动四舍五入,而普通变量则不行

本题代码


向大家问个问题,这道题怎么看出树结点的最大值呢?英文题看着头疼…

#include <cstdio>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <cstring>
#include <vector>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <ctype.h>
using namespace std;
const int maxn = 100010;
vector<int> child[maxn];
//输入中第二行是给点的是i号结点的父节点
double p, r;
int n, maxDepth = 0, num = 0;
void DFS(int index, int depth) {
	if (child[index].size() == 0) {		//到达叶节点
		if (depth > maxDepth) {		//深度比最大深度大
			maxDepth = depth;		//更新最大深度
			num = 1;				//重置最大深度的叶节点个数为1
		}
		else if (depth == maxDepth) {
			num++;
		}
		return;
	}
	for (int i = 0; i < child[index].size(); i++) {
		DFS(child[index][i], depth + 1);
	}
}
int main() {
	int father, root;
	scanf("%d%lf%lf", &n, &p, &r);
	r /= 100;
	for (int i = 0; i < n; i++) {
		scanf("%d", &father);
		if (father != -1) {
			child[father].push_back(i);
		}
		else {
			root = i;//-1的孩子结点为根结点
		}
	}
	DFS(root, 0);
	printf("%.2f %d\n", p * pow(1 + r, maxDepth), num);//四舍五入?
	return 0;
}