小球下落可看做取极限的过程

S=A+2A/2+2A/22+...+2A/2nS=A+2*A/2 + 2*A/2^2+...+2*A/2^n
=A+A(1+1/2+1/22+...+1/2n1)=A+A(1+1/2+1/2^2+...+1/2^{n-1})
=A+A12n121=A+A * \frac{1-2^{-n}}{1-2^{-1}}
=A(31/2n1)=A(3-1/2^{n-1})

xS=3A{\lim_{x \to \infty}}S = 3*A

import java.util.*;

public class Balls {
    public int calcDistance(int A, int B, int C, int D) {
        return (A+B+C+D) * 3;
    }
}