uva 839 - Not so Mobile

本文介绍了如何解决 UVA 839 的 NotsoMobile 问题,通过输入左右子树的重量和距离来判断树是否平衡,并输出相应的答案。
// uva 839 - Not so Mobile
// 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=104&page=show_problem&problem=780
// wr或wl为0的的话表示有子树,判断是否平衡, wl, dl, wr, dr 分别表示左端的重量,左端到平衡点的长度,右端的重量,右端到平衡点的长度

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int cnt_case;
bool ok;
void Init();
int Judge();
void Print();
int main(){
    cin >> cnt_case;
    while(cnt_case--){
        Init();
        Judge();
        Print();
    }
    return 0;
}
void Init(){
    ok = true;
}
int Judge(){
    int wl, wr, dl, dr;
    scanf("%d %d %d %d", &wl, &dl, &wr, &dr);
    if(wl == 0)
        wl = Judge();
    if(wr == 0)
        wr = Judge();
    if(wl * dl != wr * dr)
        ok = false;
    return wl + wr;
}   
void Print(){
    if(ok)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    if(cnt_case)
        cout << endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值