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;
}
}
}
本文介绍了一个使用Java实现的递归算法案例,该算法通过读取输入并利用递归方式解决特定问题。主要关注点在于如何定义递归条件、终止条件及如何在递归过程中更新变量状态。

被折叠的 条评论
为什么被折叠?



