PAT打卡第13天 1079. Total Sales of Supply Chain (25)

    技术2024-08-21  59

    原题链接:https://www.nowcoder.com/pat/5/problem/4309

    #pragma warning(disable:4996) #include<vector> #include<iostream> using namespace std; /* 总结:比较简单,但是犯了个弱智的错误,DFS里的起始temp_price直接赋值1.8了 像个憨憨 */ struct node { vector<int> child; int product_number; }NODE[100000]; int number; double ini_price; double rate; double total_price; void DFS(int now,int deep) { int size = NODE[now].child.size(); // 遇到叶子节点 if (size == 0) { double temp_price= ini_price; for (int i = 0; i < deep; i++) { temp_price = temp_price * (1 + rate/100); } total_price += temp_price * NODE[now].product_number; } else { // 非叶子结点 for (int i = 0; i < size; i++) { DFS(NODE[now].child[i],deep+1); } } } int main() { cin >> number >> ini_price >> rate; int num, temp_child; for (int i = 0; i < number; i++) { cin >> num; // 叶子结点 if (num == 0) { cin >> NODE[i].product_number; } // 非叶子结点 else { for (int j = 0; j < num; j++) { cin >> temp_child; NODE[i].child.push_back(temp_child); } } } DFS(0,0); printf("%.1lf", total_price); system("pause"); return 0; }

     

    Processed: 0.009, SQL: 9