首页 > 其他 > 详细

天平 (Not so Mobile UVA - 839)

时间:2018-08-25 23:25:36      阅读:262      评论:0      收藏:0      [点我收藏+]

题目描述:

技术分享图片

题目思路:

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 }

 

天平 (Not so Mobile UVA - 839)

原文:https://www.cnblogs.com/secoding/p/9535775.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!