今天参加南京银行金融科技提前批,做出来算法题还是很开心的,虽然比较简单,但还是值得记录一下
没想到还能和物理的电压计算联系起来,出题人有心了
import java.util.Scanner;
public class Program {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
String [] inputStr = sc.nextLine().split("\\s+");
Integer level;
Double r1, r2, r3, R;
level = Integer.parseInt(inputStr[0]);
r1 = Double.parseDouble(inputStr[1]);
r2 = Double.parseDouble(inputStr[2]);
r3 = Double.parseDouble(inputStr[3]);
R = Resistance(level, r1, r2, r3);
System.out.println(String.format("%.6f", R));
}
static double Resistance(Integer level, Double r1, Double r2, Double r3) {
//在此添加代码
return calculate(r1,r2,r3,level);
}
static double calculate(double r1, double r2, double r3, int n){
if(n==1){
return r1+r2+r3;
}
return r1+r2+ r3*calculate(r1,r2,r3,n-1)/(r3+calculate(r1,r2,r3,n-1));
}
}
#南京银行#