Not so Mobile UVA - 839(二叉树的先序遍历)
#include<iostream>
using namespace std;
int solve(int &W) /*这里一定要用引用,为了赋给它值*/
{
int wl, dl, wr, dr;
cin >> wl >> dl >> wr >> dr;
bool f1 = true, f2 = true;
if(!wl) f1 = solve(wl); /*沿着这个子天平找下去*/
if(!wr) f2 = solve(wr);
W = wl + wr; /*将它的重 加起来*/
return ( f1 && f2 && (wl*dl == wr*dr));
}
int main()
{
int T, W;
cin >> T;
while(T--)
{
if(solve(W))
cout << "YES" << endl;
else
cout << "NO" << endl;
if(T)
cout << endl;
}
return 0;
}
Not so Mobile UVA - 839(二叉树的先序遍历)的更多相关文章
- [LeetCode] Binary Tree Postorder Traversal 二叉树的后序遍历
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...
- [LeetCode] Binary Tree Inorder Traversal 二叉树的中序遍历
Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tre ...
- 数据结构《10》----二叉树 Morris 中序遍历
无论是二叉树的中序遍历还是用 stack 模拟递归, 都需要 O(n)的空间复杂度. Morris 遍历是一种 常数空间 的遍历方法,其本质是 线索二叉树(Threaded Binary Tree), ...
- lintcode:Binary Tree Postorder Traversal 二叉树的后序遍历
题目: 二叉树的后序遍历 给出一棵二叉树,返回其节点值的后序遍历. 样例 给出一棵二叉树 {1,#,2,3}, 1 \ 2 / 3 返回 [3,2,1] 挑战 你能使用非递归实现么? 解题: 递归程序 ...
- lintcode:二叉树的中序遍历
题目: 二叉树的中序遍历 给出一棵二叉树,返回其中序遍历 样例 给出二叉树 {1,#,2,3}, 1 \ 2 / 3 返回 [1,3,2]. 挑战 你能使用非递归算法来实现么? 解题: 程序直接来源 ...
- LeetCode(94):二叉树的中序遍历
Medium! 题目描述: 给定一个二叉树,返回它的中序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 进阶: 递归算法很简单,你可以通过迭代算法完成吗 ...
- 【LeetCode题解】94_二叉树的中序遍历
目录 [LeetCode题解]94_二叉树的中序遍历 描述 方法一:递归 Java 代码 Python代码 方法二:非递归 Java 代码 Python 代码 [LeetCode题解]94_二叉树的中 ...
- LintCode-67.二叉树的中序遍历
二叉树的中序遍历 给出一棵二叉树,返回其中序遍历. 样例 给出一棵二叉树 {1,#,2,3}, 返回 [1,3,2]. 挑战 你能使用非递归实现么? 标签 递归 二叉树 二叉树遍历 code /** ...
- LintCode-68.二叉树的后序遍历
二叉树的后序遍历 给出一棵二叉树,返回其节点值的后序遍历. 样例 给出一棵二叉树 {1,#,2,3}, 返回 [3,2,1] 挑战 你能使用非递归实现么? 标签 递归 二叉树 二叉树遍历 code / ...
随机推荐
- [LeetCode] 67. Add Binary 二进制数相加
Given two binary strings, return their sum (also a binary string). The input strings are both non-em ...
- IDEA进行activiti-archetype-unittest脚手架的安装
官网:https://www.activiti.org/ 第一步:下载activiti源码(https://github.com/Activiti/Activiti/tags) 第二步:在termin ...
- POJ 1014 Dividing(入门例题一)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: Accepted: Description Marsha and Bill own ...
- eslint 验证vue文件 报错 unexpected token =解决方法
解决方案:.eslintrc更改文件配置 { "extends": [ 'standard' ], "parserOptions": { "parse ...
- IDEA 自定义代码模板
IDEA 自定义代码模板操作步骤:
- java笔记3
面向对象的特点: 1.封装: 2.继承 3.多态 好处: 是一种符合人们思考习惯的思想 可以将复杂的事情简单化 将程序员从执行者变为指挥者 二 类与对象 成员变量与局部变量的区别: ...
- 隐藏GridControl的“Drag a column header here to group by that column”
打开设计器,找到OptionsView,往下拉设置showGroupPanel为false
- PB 计算公式算出结果赋值给另外一列
在数据窗口中添加一个公式列 --在itmchanged事件中写的计算赋值代码 String ls_gs,ls_sqldecimal{2} ls_gsjg if dwo.name='gs1' then ...
- kafka和zookeeper安装部署(版本弄不好就是坑)
yum install -y unzip zip 配置host vi /etc/host172.19.68.10 zk1 1. zookeeper zookeeper下载地址 http://mirro ...
- 方法2:使用Jenkins构建Docker镜像 --SpringCloud
前提意义: SpringCloud微服务里包含多个文件夹,拉取仓库的所有代码,然后过根据选项参数使用maven编译打包指定目录的jar,然后再根据这个目录的Dockerfile文件制作Docker镜像 ...