目录
1,题目描述
题目大意
2,思路
3,AC代码
4,解题过程
Sample Input:
9 1.80 1.00
1 5 4 4 -1 4 5 3 6
Sample Output:
1.85 2
求一个供应链中,货物可以卖出的最高价,以及卖出最高价的零售商数目
和这一题很像@&再见萤火虫&【PAT_甲级_1079 Total Sales of Supply Chain (25point(s)) (C++)【DFS/scanf接受double】】
#include
using namespace std;
double P, r;
int N, maxDep = 0, num = 0;
vector data[100003];
void dfs(int r, int dep){
if(data[r].size() == 0){
if(dep > maxDep){
maxDep = dep;
num = 1;
}else if(dep == maxDep)
num++;
}
for(int i = 0; i < data[r].size(); i++)
dfs(data[r][i], dep + 1);
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
scanf("%d %lf %lf", &N, &P, &r);
int id, root;
for(int i = 0; i < N; i++){
scanf("%d", &id);
if(id == -1)
root = i;
else
data[id].push_back(i);
}
dfs(root, 0);
printf("%.2f %d", P * pow(1 + r / 100, maxDep), num);
return 0;
}
一发入魂