zoukankan      html  css  js  c++  java
  • UVA 839 Not so Mobile (递归建立二叉树)

    题目连接:http://acm.hust.edu.cn/vjudge/problem/19486

    给你一个杠杆两端的物体的质量和力臂,如果质量为零,则下面是一个杠杆,判断是否所有杠杆平衡。

    分析:递归。直接递归求解即可。

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <string>
    #include <set>
    #include <map>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <list>
    #include<functional>
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define pi acos(-1.0)
    using namespace std;
    typedef long long ll;
    const int N=300;
    const int M=15005;
    int flag;  
    int tree()  
    {  
        int Wl,Dl,Wr,Dr;  
        scanf("%d%d%d%d",&Wl,&Dl,&Wr,&Dr);  
        if (!Wl) Wl = tree();  
        if (!Wr) Wr = tree();  
        if (Wl*Dl != Wr*Dr) flag = 0;  
        return Wl+Wr;  
    }  
      
    int main()  
    {  
        int T;  
        while (cin >> T)  
        while (T --) {  
            flag = 1;  
            tree();  
            if (flag)  
                printf("YES
    ");  
            else printf("NO
    ");  
            if (T) printf("
    ");  
        }  
        return 0;  
    }  
    View Code
  • 相关阅读:
    公司实习职位与要求
    段子
    Python 练习项目1 弹球游戏
    精准控制PWM脉冲的频率和数量
    ST Link 调试问题总结
    验证
    大道至简(第六章)读后感
    动手动脑
    大道至简(第五i章)读后感
    数组课后作业
  • 原文地址:https://www.cnblogs.com/jianrenfang/p/5738303.html
Copyright © 2011-2022 走看看