题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=780
思路:递归访问二叉树
Code:
#include <iostream>
#include <cstdio>
using namespace std;
bool solve(int &w){
int w1,d1,w2,d2;
bool b1 = true , b2 = true;
cin >> w1 >> d1 >> w2 >> d2 ;
if( !w1 ){ b1 = solve(w1); }
if( !w2 ){ b2 = solve(w2); }
w = w1 + w2;
return b1 && b2 && ( w1 * d1 == w2 * d2 );
}
int main(){
int T;
int w ;
cin >> T;
while( T-- ){
if( solve(w) ){
cout << "YES" << endl;
}else {
cout << "NO" << endl;
}
if(T) cout << endl;
}
return 0;
}