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
  • 相关阅读:
    linux命令大全
    IP协议
    TCP、IP、ARP协议之间的工作关系
    程序出现问题后
    HTTP(超文本传输协议)
    多线程
    syslog.conf文件
    logger命令
    gdb
    二、数据的存储结构
  • 原文地址:https://www.cnblogs.com/jianrenfang/p/5738303.html
Copyright © 2011-2022 走看看