题目连接: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=;
const int M=;
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 = ;
return Wl+Wr;
} int main()
{
int T;
while (cin >> T)
while (T --) {
flag = ;
tree();
if (flag)
printf("YES\n");
else printf("NO\n");
if (T) printf("\n");
}
return ;
}

UVA 839 Not so Mobile (递归建立二叉树)的更多相关文章

  1. UVA.839 Not so Mobile ( 二叉树 DFS)

    UVA.839 Not so Mobile ( 二叉树 DFS) 题意分析 给出一份天平,判断天平是否平衡. 一开始使用的是保存每个节点,节点存储着两边的质量和距离,但是一直是Runtime erro ...

  2. UVa 839 -- Not so Mobile(树的递归输入)

    UVa 839 Not so Mobile(树的递归输入) 判断一个树状天平是否平衡,每个测试样例每行4个数 wl,dl,wr,dr,当wl*dl=wr*dr时,视为这个天平平衡,当wl或wr等于0是 ...

  3. UVa 839 Not so Mobile (递归思想处理树)

    Before being an ubiquous communications gadget, a mobilewas just a structure made of strings and wir ...

  4. uva 839 not so mobile——yhx

    Not so Mobile  Before being an ubiquous communications gadget, a mobile was just a structure made of ...

  5. Uva 839 Not so Mobile

    0.最后输出的yes no的大小写 1.注意 递归边界   一直到没有左右子树 即b1=b2=false的时候 才返回 是否 天平平衡. 2.注意重量是利用引用来传递的 #include <io ...

  6. UVa 699 The Falling Leaves(递归建树)

    UVa 699 The Falling Leaves(递归建树) 假设一棵二叉树也会落叶  而且叶子只会垂直下落   每个节点保存的值为那个节点上的叶子数   求所有叶子全部下落后   地面从左到右每 ...

  7. [LeetCode] Construct Binary Tree from Preorder and Inorder Traversal 由先序和中序遍历建立二叉树

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  8. UVa 839 天平

    原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  9. LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal (用先序和中序树遍历来建立二叉树)

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

随机推荐

  1. C++——继承时的this指针

    1.this指针只在类的成员函数中使用,当类的成员函数需要用到自己的指针时就要用到this指针.但静态函数不能使用this关键字,其解释是:因为this是个引用,哪个对象调用方法就引用哪个对象. 而静 ...

  2. Tomcat-Jdbc-Pool连接池参数说明

    原文  http://liuxing.info/2016/01/05/Tomcat-Jdbc-Pool参数说明/ 转载收藏用,如有侵权,请联系删除,谢谢. 介绍 Tomcat 在 7.0 以前的版本都 ...

  3. taotao用户登录springMVC拦截器的实现

    在springMVC中写拦截器,只需要两步: 一.写 java 拦截器类,实现 interceptor 拦截器接口. 二.在 springMVC 的xml配置文件中,配置我们创建的拦截器对象及其拦截目 ...

  4. HDU 1203 01背包

    I NEED A OFFER! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  5. spring 中的@Import注解和@ImportResource注解

    概述:@Import注解是引入带有@Configuration的java类. @ImportResource是引入spring配置文件.xml 案例的核心代码如下: package com.timo. ...

  6. 在Maven中怎么配置外部Jar

    转摘自:http://liugang594.iteye.com/blog/1677712 假设我们有一个Maven的project,其中有些Jar包不是来自Maven库的,是存在本地的某些Jar文件, ...

  7. Hibernate 懒加载 错误----no session

    错误: unable to evaluate the expression Method threw 'org.hibernate.LazyInitializa org.hibernate.LazyI ...

  8. 04-plis属性列表

      源代码下载链接:04-plis属性列表.zip27.8 KB // MJPerson.h // //  MJPerson.h //  04-plis属性列表 // //  Created by a ...

  9. [bzoj1251]序列终结者——splay

    题目大意 网上有许多题,就是给定一个序列,要你支持几种操作:A.B.C.D.一看另一道题,又是一个序列 要支持几种操作:D.C.B.A.尤其是我们这里的某人,出模拟试题,居然还出了一道这样的,真是没技 ...

  10. bzoj 2324 ZJOI 营救皮卡丘 费用流

    题的大概意思就是给定一个无向图,边有权值,现在你有k个人在0点,要求走到n点,且满足 1:人们可以分头行动,可以停在某一点不走了 2:当你走到x时,前x-1个点必须全部走过(不同的人走过也行,即分两路 ...