UVA - 839 Not so Mobile
2014-10-13 00:03
381 查看
题目大意:求两边天平是否相等
解题思路:用递归,因为如果天平上为零的话就要继续读,在用一个全局变量记录是否平衡,这样就不怕在递归的过程中导致不平衡发生而被跳过
解题思路:用递归,因为如果天平上为零的话就要继续读,在用一个全局变量记录是否平衡,这样就不怕在递归的过程中导致不平衡发生而被跳过
#include<cstdio> int mark ; int judge() { int num[4]; for(int i = 0; i < 4; i++) { scanf("%d", &(num[i])); // printf("%d\t",num[i]); } // printf("\n"); if(num[0] == 0) num[0] = judge(); if(num[2] == 0) num[2] = judge(); if(num[0] * num[1] != num[2] * num[3]) mark = 0; return num[0] + num[2]; } int main() { int test; scanf("%d", &test); while(test--) { mark = 1; int temp = judge(); if(mark == 0) printf("NO\n"); else printf("YES\n"); if(test) printf("\n"); } return 0; }
相关文章推荐
- uva 839 - Not so Mobile
- uva-839 Not so Mobile
- UVA 839 - Not so Mobile(dfs就可以)
- Uva839 Not so Mobile 【递归输入】【例题6-9】
- UVA839 Not so Mobile
- UVA839 - Not so Mobile
- UVA839 - Not so Mobile
- UVa 839 - Not so Mobile
- Not so Mobile UVA 839
- Not so Mobile UVA - 839
- uva839-Not so Mobile-二叉树的DFS
- 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