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;
}
简单题, 用杠杆原理判断是否平衡
没有经验, 一开始就构造了一个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;
}
相关文章推荐
- 创客张江 招募
- 代码面试之串
- LeetCode-Evaluate Reverse Polish Notation
- JS处理json日期格式化问题
- qt 委托 delegate
- Longest Palindromic Substring
- [教程]如何使用V7包中ActionBar(Eclipse版)
- ISA TEST Writeup
- http://code.662p.com/view/5141.html
- 一起学习android图像缩放资源 (27)
- Combination Sum III
- 转:DLL如何导出C++的类
- 虚拟内存
- Error during bitstream generation
- Ubuntu 15.10 会从此摘掉“乏味的升级版”这顶帽子吗?
- 虚拟内存
- 代码大全2读后感(1)
- JS日期格式化之javascript Date format
- The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
- dp_Pku1887