天平 (Not so Mobile UVA - 839)
题目描述:

题目思路:
1.DFS建树
2.只有每个树的左右子树都平衡整颗树才平衡
#include <iostream>
using namespace std; bool solve(int& w)
{
int d1,w1,d2,w2;
cin >> w1 >> d1 >> w2 >> d2 ;
bool b1 = true ,b2 = true ;
if(!w1) b1 = solve(w1) ;
if(!w2) b2 = solve(w2) ;
w = w1 + w2 ;
return (b1 && b2 && (w1 * d1 == w2 * d2)) ;
} int main(int argc, char *argv[])
{
int t,w;
scanf("%d",&t) ;
while(t--)
{
if(solve(w)) cout << "YES" << endl;
else cout << "NO" << endl ;
if(t) cout << endl ;
}
return ;
}
天平 (Not so Mobile UVA - 839)的更多相关文章
- 【紫书】【重要】Not so Mobile UVA - 839 递归得漂亮
题意:判断某个天平是否平衡,输入以递归方式给出. 题解:递归着输入,顺便将当前质量作为 &参数 维护一下,顺便再把是否平衡作为返回值传回去. 坑:最后一行不能多回车 附:天秀代码 #defin ...
- Not so Mobile UVA - 839
题目链接:https://vjudge.net/problem/UVA-839 题目大意:输入一个树状天平,根据力矩相等原则,判断是否平衡. 如上图所示,所谓力矩相等,就是Wl*Dl=Wr*Dr. ...
- Not so Mobile UVA - 839(二叉树的先序遍历)
#include<iostream> using namespace std; int solve(int &W) /*这里一定要用引用,为了赋给它值*/ { int wl, dl ...
- UVA.839 Not so Mobile ( 二叉树 DFS)
UVA.839 Not so Mobile ( 二叉树 DFS) 题意分析 给出一份天平,判断天平是否平衡. 一开始使用的是保存每个节点,节点存储着两边的质量和距离,但是一直是Runtime erro ...
- UVa 839 -- Not so Mobile(树的递归输入)
UVa 839 Not so Mobile(树的递归输入) 判断一个树状天平是否平衡,每个测试样例每行4个数 wl,dl,wr,dr,当wl*dl=wr*dr时,视为这个天平平衡,当wl或wr等于0是 ...
- UVa 839 Not so Mobile (递归思想处理树)
Before being an ubiquous communications gadget, a mobilewas just a structure made of strings and wir ...
- Uva 839 Not so Mobile
0.最后输出的yes no的大小写 1.注意 递归边界 一直到没有左右子树 即b1=b2=false的时候 才返回 是否 天平平衡. 2.注意重量是利用引用来传递的 #include <io ...
- uva 839 not so mobile——yhx
Not so Mobile Before being an ubiquous communications gadget, a mobile was just a structure made of ...
- UVa 839 天平
原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
随机推荐
- POJ 3984 迷宫问题(简单bfs+路径打印)
传送门: http://poj.org/problem?id=3984 迷宫问题 Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- UIScrollView的常用属性
UIScrollView的常用属性
- webservice 从客户端中检测到有潜在危险的 Request.Form 值
webservice中传递xml格式的参数时报错 webservice 从客户端中检测到有潜在危险的 Request.Form 值解决方案: 1.在web.config的system.web节点中添加 ...
- EF Core怎么只Update实体的部分列数据
下面是EF Core中的一个Person实体: public partial class Person { public int Id { get; set; } public string Code ...
- iOS:动画(18-10-15更)
目录 1.UIView Animation 1-1.UIView Animation(基本使用) 1-2.UIView Animation(转场动画) 2.CATransaction(Layer版的U ...
- Python 基础 变量和数据类型
python 数据类型 一,整数,可以出来任意大小的整数. 如 1, 100, -8080,0 等等. 二,浮点数,浮点数也可以被成为小数. 三,字符串,字符串是以'' 或"". ...
- layui form表单 input输入框获取焦点后 阻止Enter回车自动提交
最简单的解决办法,不影响其他操作,给提交按钮增加 type="button" 属性 完美解决 <button type="button" class=&q ...
- wso2 ei 6.4.0安装笔记
目的:将最新版(6.4.0)部署在linux服务器,与Api Manager部署在同一环境 环境: Centos 7.3 Jdk 8 Mysql 5.7 问题一: 将H2替换为Mysql5.7数据库时 ...
- DataSet转换为泛型集合和DataRow 转成 模型类
public static class TransformToList { /// <summary> /// DataSet转换为泛型集合 /// </summary> // ...
- python学习笔记:第15天 初识面向对象
目录 1. 面向对象和面向过程 2. 面向对象如何编写: 3. 面向对象的三大特征 封装 继承 多态 1. 面向对象和面向过程 面向对象和面向过程的理解: ⾯向过程: ⼀切以事物的流程为核⼼. 核⼼是 ...