Problem Description
甜甜從小就喜歡畫圖畫,最近他買了一支智能畫筆,由於剛剛接觸,所以甜甜只會用它來畫直線,於是他就在平面直角坐標系中畫出如下的圖形:

甜甜的好朋友蜜蜜發現上面的圖還是有點規則的,於是他問甜甜:在你畫的圖中,我給你兩個點,請你算一算連接兩點的折線長度(即沿折線走的路線長度)吧。
Input
第一個數是正整數N(≤100)。代表數據的組數。
每組數據由四個非負整數組成x1,y1,x2,y2;所有的數都不會大於100。
Output
對於每組數據,輸出兩點(x1,y1),(x2,y2)之間的折線距離。注意輸出結果精確到小數點後3位。
Sample Input
5
0 0 0 1
0 0 1 0
2 3 3 1
99 99 9 9
5 5 5 5
Sample Output
1.000
2.414
10.646
54985.047
0.000
import java.io.BufferedInputStream;
import java.text.DecimalFormat;
import java.util.*;
public class Main {
public static void main(String[] args) {
int k;
int x1,x2,y1,y2;
Scanner sc=new Scanner(new BufferedInputStream(System.in));
DecimalFormat dec=new DecimalFormat("0.000");
k=sc.nextInt();
for(int i=0;i<k;i++){
x1=sc.nextInt();
y1=sc.nextInt();
x2=sc.nextInt();
y2=sc.nextInt();
double sum=Math.abs(fun(x1,y1)-fun(x2,y2));
System.out.println(dec.format(sum));
}
}
public static double fun(int x,int y){
double sum=0;
double r=Math.sqrt(2);
int n=x+y;
for(int i=1;i<n;i++){
sum+=(i*r);
}
sum+=(x*r);
for(int i=0;i<n;i++){
sum+=Math.sqrt(Math.pow(i, 2)+Math.pow(i+1, 2));
}
return sum;
}
}