UVA 839 Not so Mobile (递归建立二叉树)
2016-08-04 20:34
453 查看
题目连接:http://acm.hust.edu.cn/vjudge/problem/19486
给你一个杠杆两端的物体的质量和力臂,如果质量为零,则下面是一个杠杆,判断是否所有杠杆平衡。
分析:递归。直接递归求解即可。
View Code
给你一个杠杆两端的物体的质量和力臂,如果质量为零,则下面是一个杠杆,判断是否所有杠杆平衡。
分析:递归。直接递归求解即可。
#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=300; const int M=15005; 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 = 0; return Wl+Wr; } int main() { int T; while (cin >> T) while (T --) { flag = 1; tree(); if (flag) printf("YES\n"); else printf("NO\n"); if (T) printf("\n"); } return 0; }
View Code
相关文章推荐
- 例题6-9UVA839 - Not so Mobile 递归访问二叉树
- UVa 839 (递归方式读取二叉树) Not so Mobile
- UVA839 Not so Mobile【二叉树】【递归】
- uva839 Not so Mobile (重建二叉树)
- UVa 839 Not so Mobile(树的递归输入)
- (UVA - 839) Not so Mobile(递归+引用,树的先序遍历)
- uva839-Not so Mobile-二叉树的DFS
- UVa - 839 - Not so Mobile(二叉树的DFS)
- UVa 839 Not so Mobile (DFS二叉树)
- UVa 839 - Not so Mobile【递归】
- uva 839 (Not so mobile)天平 ---递归输入
- UVA 839 Not so Mobile(二叉树|DFS)
- UVA 839 Not so Mobile(二叉树经典题)
- Uva839 Not so Mobile 【递归输入】【例题6-9】
- UVa839 Not so Mobile
- uva 839 - Not so Mobile
- uva_839_Not so Mobile
- uva 839 - Not so Mobile
- UVa839 Not so Mobile
- 839 - Not so Mobile--递归水题