题目描述:
题目思路:
1.DFS建树
2.只有每个树的左右子树都平衡整颗树才平衡
1 #include <iostream> 2 using namespace std; 3 4 bool solve(int& w) 5 { 6 int d1,w1,d2,w2; 7 cin >> w1 >> d1 >> w2 >> d2 ; 8 bool b1 = true ,b2 = true ; 9 if(!w1) b1 = solve(w1) ; 10 if(!w2) b2 = solve(w2) ; 11 w = w1 + w2 ; 12 return (b1 && b2 && (w1 * d1 == w2 * d2)) ; 13 } 14 15 int main(int argc, char *argv[]) 16 { 17 int t,w; 18 scanf("%d",&t) ; 19 while(t--) 20 { 21 if(solve(w)) cout << "YES" << endl; 22 else cout << "NO" << endl ; 23 if(t) cout << endl ; 24 } 25 return 0; 26 }
原文地址:https://www.cnblogs.com/secoding/p/9535775.html
时间: 2024-10-09 21:41:00