UVA 839 Recursive _ recursion

Source: Internet
Author: User

Enter a tree balance to determine whether the balance is based on the moment equality principle. As shown in Figure 6-5, the so-called torque is equal to the W l l =w R D R, where W L and W R are the weights of the left and right sides, D is the distance. In recursive (first order) mode input: The format of each balance is w L, D L, W R, D R, when W L or W R is 0 o'clock, means that the "weight" is actually a sub scale, then the child balance will be described. When the W l =w r = 0 o'clock, the Zoozi balance is described first, then the right sub balance.
Sample Input
1
0 2 0 4
0 3 0 1
1 1 1 1
2 4 4 2
1 6 3 2
Sample Output
YES

 #include <bits/stdc++.h> const int INF = 0x3f3f3f3f; Const int MAXN = 100005;


#define MST (S,Q) memset (s,q,sizeof (s)) #define Lchild id<<1 #define RCHILD (id<<1) +1 using namespace std;
    BOOL Solve (int &w) {int W1, D1, W2, D2;
    CIN >> W1 >> D1 >> W2 >> D2;
    BOOL Sign1 = 1, sign2 = 1; if (!
    W1) Sign1 = Solve (W1); if (!
    W2) sign2 = Solve (W2);
    W = W1 + W2;
return sign1 && sign2 && (W1 * D1 = = W2 * D2);
    int main () {int T, W;
    Cin >> T;
        while (t--) {if (Solve (W)) cout << "yes\n";
        else cout << "no\n";
    if (T) cout << Endl; }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.