UVA-839 Not so Mobile
来源:互联网 发布:网络摄像头存储计算 编辑:程序博客网 时间:2024/05/18 02:10
UVA-839 Not so Mobile
题目大意:每个天平会给出 wl,dl,wr,dr分别是左边重量,左边力臂长,右边重量,右边力臂长,如果重量为0则表示这边挂了一个天平,也会给出如下信息,然后这个天平这边的重量等于它下面挂的所有的质量和。要判断给出的所有天平是否都平衡。
解题思路:dfs 遍历其左天盘 然后遍历 右天盘 每次遍历 返回其左右天盘的值 然后用相应方向的天盘 的质量 加上其子天盘的质量
/************************************************************************* > File Name: UVA-839.cpp > Author: Robin > Mail: 499549060@qq.com > Created Time: 2016年07月27日 星期三 20时15分01秒 ************************************************************************/#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<cstring>using namespace std;int flag = 1;int dfs () { int wl,dl, wr,dr; scanf("%d%d%d%d",&wl,&dl,&wr,&dr); if (wl == 0) wl += dfs(); if (wr == 0) wr += dfs(); if (wl*dl != wr*dr) flag = 0; return wl+wr;}int main () { int N; scanf("%d", &N); while (N--) { flag = 1; int t = dfs(); if (flag) printf("YES\n"); else printf("NO\n"); if (N) printf("\n"); }}
0 0
- uva 839 - Not so Mobile
- uva 839 Not so Mobile
- uva 839 - Not so Mobile
- UVa 839 - Not so Mobile
- UVa 839 - Not so Mobile
- uva-839 Not so Mobile
- uva 839 - Not so Mobile
- UVA 839 Not so Mobile
- uva 839 Not so Mobile
- Not so Mobile UVA 839
- uva 839 - Not so Mobile
- uva 839 Not so Mobile
- UVa 839 - Not so Mobile
- UVA - 839 Not so Mobile
- UVA 839 Not so Mobile
- UVA - 839 Not so Mobile
- UVA 839 - Not so Mobile
- UVA - 839 Not so Mobile
- AngularJS之ng-repeat指令
- 数据挖掘中的矩阵基础(1)
- tjut 4746
- Redis入门实战(附源码)
- 约瑟夫环的链表实现
- UVA-839 Not so Mobile
- HDU 4455 Substrings dp
- UVA-10562 Undraw the Trees
- UVA-572 Oil Deposits
- oracle11g静默安装
- UVA-657 The die is cast
- UVA-784 Maze Exploration
- POJ2559 单调队列
- java编程思想 bruce Eckel chapter2一切都是对象