zoukankan      html  css  js  c++  java
  • UVA 839 Not so Mobile 数据结构

      题目链接: UVA

      题目大意: 给出一颗树, 给出每个叶子的权值和力矩, 问这棵树平衡不平衡

      解题思路: 由于叶子节点的输入是递归给出的, 所以编写递归进行输入比较好

      代码: 

    #include <iostream>
    #include <queue>
    #include <string>
    #include <vector>
    #include <algorithm>
    #include <list>
    #include <iterator>
    #include <cmath>
    #include <cstring>
    #include <forward_list>
    #include <sstream>
    using namespace std;
    
    bool solve() {
        int lw, ld, rw, rd;
        cin >> lw >> ld  >> rw >> rd;
        int ret1=1;
        int ret2=1;
        if(!lw) ret1 = solve();
        if(!rw) ret2 = solve();
        return  ret1 && ret2 && lw * ld == rw * rd;
    }
    
    int main() {
        freopen("in.txt", "r", stdin);
        int t;
        cin >> t;
        while(t--) {
            if(solve()) {
                cout << "YES" << endl;
            }    
            else {
                cout << "NO" << endl;
            }
        }
    }
    View Code

      思考: 总是要学习新的姿势啊 ,递归输入的话就要递归写。 而且这个根本不用建树啊, 最后只输出Yes  or  NO 。

      

  • 相关阅读:
    js触摸屏案例
    Docker
    Docker 镜像加速
    Docker 命令大全
    linux gpasswd
    Docker基础教程
    PHP输出毫秒时间戳
    PHP Variable handling 函数
    Partition Array by Odd and Even
    Median
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/8027152.html
Copyright © 2011-2022 走看看