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 / ...
随机推荐
- Jenkenis报错:该jenkins实例似乎已离线
使用运行war的形式安装jenkins,因为伟大的墙出现,“该jenkins实例似乎已离线” 问题 解决方法: 1. 保留此离线页面,重新开启一个浏览器tab标签页 2.输入输入网址http://lo ...
- Kubernetes 控制器之 Service 讲解(七)
一.背景介绍 我们这里准备三台机器,一台master,两台node,采用kubeadm的方式进行安装的,安装过程大家可以参照我之前的博文. IP 角色 版本 192.168.1.200 master ...
- 【视频开发】关于FFMPEG中内存泄漏的问题之av_bitstream_filter_filter
How may I free pkt in an ffmpeg write frame method Rate this: See more: C++ ffmpeg Greetings I' ...
- FPGA程序编译后逻辑单元数为0
问题 FPGA代码写完后编译不报错,但是显示使用的逻辑单元数(Total logic elements)为0.当然程序也不工作. 我用的是Intel Altera FPGA,verilog语言,在Qu ...
- 文件上传速度查询方法(watch工具)
由于业务迁移,需要将大量文件拷贝到目标机器上的/mnt目录,在拷贝过程中,想要查看上传的速度,做法如下:[root@mail01 ~]# du -sh /mnt5.6G /mnt[root@mail0 ...
- TCP/IP学习笔记18--TCP--拥塞控制 (慢开始, 拥塞避免, 快重传和快恢复)
用最多的梦面对未来 -- 李嘉诚 在某段时间,若对网络资源的需求超过了该资源所能提供 ...
- LeetCode 162. 寻找峰值(Find Peak Element) 29
162. 寻找峰值 162. Find Peak Element 题目描述 峰值元素是指其值大于左右相邻值的元素. 给定一个输入数组 nums,其中 nums[i] ≠ nums[i+1],找到峰值元 ...
- 【RocketMQ源码学习】- 4. Client 事务消息源码解析
介绍 > 基于4.5.2版本的源码 1. RocketMQ是从4.3.0版本开始支持事务消息的. 2. RocketMQ的消息队列能够保证生产端,执行数据和发送MQ消息事务一致性,而消费端的事务 ...
- Elasticsearch-6.7.0系列(八)开启kibana监控
修改ES配置: 修改elasticsearch.yml,添加如下xpack配置: xpack.security.enabled: true xpack.ml.enabled: true xpack.l ...
- 转 C# 使用openssl
//先用大整数来生成一个1024bit的密钥对 RSA rsa = new RSA(); BigNumber number = OpenSSL.Core.Random.Next(10, 10, 1); ...