(递归)【UVA 839】Not so Mobile

题目链接:https://vjudge.net/problem/UVA-839

简单递归,参考了刘汝佳的代码。

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN = 1000+10;

bool solve(int& w)
{
    int w1,d1,w2,d2;
    cin>>w1>>d1>>w2>>d2;
    bool a = true,b = true;
    if(!w1)
        a = solve(w1);
    if(!w2)
        b = solve(w2);
    w = w1+w2;//通过引用传递 子天平的重量
    return a && b && (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<<'\n';
    }
}

猜你喜欢

转载自blog.csdn.net/suiguia/article/details/80626623
今日推荐