首页 > 代码库 > UVa839 Not so Mobile (二叉树的DFS)

UVa839 Not so Mobile (二叉树的DFS)

链接:http://acm.hust.edu.cn/vjudge/problem/19486
分析:二叉树模型的DFS。输入是采用递归方式输入,直接变读边判断就行。

 1 #include <cstdio> 2  3 bool solve(int& W) { 4     int W1, D1, W2, D2; 5     scanf("%d%d%d%d", &W1, &D1, &W2, &D2); 6     bool b1 = true, b2 = true; 7     if (!W1) b1 = solve(W1); 8     if (!W2) b2 = solve(W2); 9     W = W1 + W2;10     return b1 && b2 && (W1 * D1 == W2 * D2);11 }12 13 int main() {14     int T, W;15     scanf("%d", &T);16     while (T--) {17         if (solve(W)) printf("YES\n"); else printf("NO\n");18         if (T) printf("\n");19     }20     return 0;21 }

 

UVa839 Not so Mobile (二叉树的DFS)