目录
1,题目描述
题目大意
2,思路
3,AC代码
4,解题过程
1,题目描述
Sample Input:
10 1.80 1.00
3 2 3 5
1 9
1 4
1 7
0
2 6 1
1 8
0
0
0
Sample Output:
1.8362 2
题目大意
在供应链形成的过程中,每经过一个节点,价格增长一定的百分比,输出售价最小的价格,以及以此价格售卖的零销商的数目。
2,思路
1,构建供应链:
2,dfs算法:
3,AC代码
#include<bits/stdc++.h>
using namespace std;
int N, ways = 0;
double P, r, minPrice = 99999999;
vector<int> tree[100002];
void dfs(int start, double price){
if(tree[start].size() == 0){
if(price < minPrice){
minPrice = price;
ways = 1;
}else if(price == minPrice)
ways++;
}
for(int i = 0; i < tree[start].size(); i++)
dfs(tree[start][i], price * (1+r));
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
scanf("%d %lf %lf\n", &N, &P, &r);
r /= 100;
int num, id;
for(int i = 0; i < N; i++){
scanf("%d", &num);
for(int j = 0; j < num; j++){
scanf("%d", &id);
tree[i].push_back(id);
}
}
dfs(0, P);
printf("%.4f %d", minPrice, ways);// !!!是%.4f 不是%.4lf
return 0;
}
4,解题过程
注意
1,dfs中的价格的迭代
2,输出格式:
一发入魂(第三次遇到类似的题目)