uva 839 (Not so mobile)天平 ---递归输入
2017-03-07 11:24
405 查看
java的写法
import java.util.Scanner;
public class Main {
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
int T = scan.nextInt();
while(T--!=0){
if(solve(new M(0))){
System.out.println("YES");
}else{
System.out.println("NO");
}
if(T!=0)System.out.println();
}
}
private static boolean solve(M w) {
M wl = new M(scan.nextInt());
M dl = new M(scan.nextInt());
M wr = new M(scan.nextInt());
M dr = new M(scan.nextInt());
boolean b1 = true,b2 = true;
if(wl.value==0)b1 = solve(wl);
if(wr.value==0)b2 = solve(wr);
w.value = wl.value+wr.value;
return b1&&b2&&wl.value*dl.value==wr.value*dr.value;
}
static class M{
public int value;
public M(int value){
this.value = value;
}
}
}
import java.util.Scanner;
public class Main {
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
int T = scan.nextInt();
while(T--!=0){
if(solve(new M(0))){
System.out.println("YES");
}else{
System.out.println("NO");
}
if(T!=0)System.out.println();
}
}
private static boolean solve(M w) {
M wl = new M(scan.nextInt());
M dl = new M(scan.nextInt());
M wr = new M(scan.nextInt());
M dr = new M(scan.nextInt());
boolean b1 = true,b2 = true;
if(wl.value==0)b1 = solve(wl);
if(wr.value==0)b2 = solve(wr);
w.value = wl.value+wr.value;
return b1&&b2&&wl.value*dl.value==wr.value*dr.value;
}
static class M{
public int value;
public M(int value){
this.value = value;
}
}
}
相关文章推荐
- UVa 839 Not so Mobile(树的递归输入)
- Uva839 Not so Mobile 【递归输入】【例题6-9】
- UVa 839-Not so Mobile(天平)
- uva 839 Not so Mobile 输入外挂
- UVA 839 Not so Mobile (递归建立二叉树)
- UVA839 Not so Mobile【二叉树】【递归】
- 例题6-9UVA839 - Not so Mobile 递归访问二叉树
- (UVA - 839) Not so Mobile(递归+引用,树的先序遍历)
- uva 839 Not so Mobile 天平问题
- 天平 (Not so Mobile, UVa 839)
- Uva839 Not so Mobile(天平)
- UVa 839 (递归方式读取二叉树) Not so Mobile
- UVa 839 - Not so Mobile【递归】
- UVA839 - Not so Mobile
- uva 839 Not so Mobile
- UVa 839 Not so Mobile (DFS二叉树)
- uva 839 - Not so Mobile
- Not so Mobile UVA 839
- uva-839 Not so Mobile
- UVa 839 - Not so Mobile