您的位置:首页 > 其它

uva 839

2015-10-01 08:40 387 查看
原题

简单题, 用杠杆原理判断是否平衡

没有经验, 一开始就构造了一个struct, 

但是AC之后去翻了别人的代码, 发现没啥必要

因为这些数据判断完一次就没用了, 干嘛要存起来呢

还有就是又被这个坑给坑到了....

两个case之间需要空行 , 意味着最后一个case输出完后不需要空行

牢记!!!! 

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <cassert>
#include <iomanip>

using namespace std;
/*
uva 839
注意 : 1.不需要存储, 仅仅是用于判断的情况下可以不用自己构造struct, 因为判断完一次数据就没用了
2.凡是题目提到两个case之间需要空行的, 要知道最后一个case结果输出完毕就不能有空行了
*/

bool isBalance;

struct mobile{
int W1,W2;
int D1,D2;
mobile * left, *right;
mobile(){ W1=W2=D1=D2=0;
left = right = NULL; }
};
typedef mobile * Node;

Node GetNode(){
Node res = new mobile;
cin >> res->W1 >> res->D1 >> res->W2 >> res->D2;
if( res->W1==0 ){
res->left = GetNode();
res->W1 = res->left->W1 + res->left->W2;
}
if( res->W2==0 ){
res->right = GetNode();
res->W2 = res->right->W1 + res->right->W2;
}
if( res->W1*res->D1 != res->W2*res->D2 ){
isBalance = false;
}
return res;
}

void Delete(Node node){
if( node->left ) Delete(node->left);
if( node->right ) Delete(node->right);
delete node;
return ;
}

int main(){
// freopen("input2.txt","r",stdin);
int T, W1,W2,D1,D2;
scanf("%d ",&T);
while( T-- ){
isBalance = true;
Node root = GetNode();
// cout << root->W1 << " " << root->W2 << endl;
if( isBalance ){
cout << "YES" << endl;
}else{
cout << "NO" << endl ;
}
if( T ) cout << endl;
}
return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: