天平

 

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

bool solve(int &w)
{
    int w1, w2, d1, d2;
    cin >> w1 >> d1 >> w2 >> d2;
    bool left = true, right = true;
    if(!w1)left = solve(w1);//一举两得,将w1和2用引用的方式传入下一个递归函数中,可以将w1和2的值改变,改为下一个地方两个称重量之和,如果子称想等的话就是true
    if(!w2)right = solve(w2);
    w = w1 + w2;
    return left && right && (w1 * d1 == w2 * d2);
}
int main(void)
{
    int T,w;
    cin >> T;
    while (T--)
    {
        if (solve(w)) cout << "YES\n";
        else cout << "NO\n";
        if (T)cout << endl;
    }
    return 0;
}

 

posted @ 2021-02-08 19:29  loliconsk  阅读(89)  评论(0)    收藏  举报