HDU 2073 无限的路
Problem Description
 甜甜从小就喜欢画图画,最近他买了一支智能画笔,由于刚刚接触,所以甜甜只会用它来画直线,于是他就在平面直角坐标系中画出如下的图形: 
 
  
   ![]() 
    
  
 
  
甜甜的好朋友蜜蜜发现上面的图还是有点规则的,于是他问甜甜:在你画的图中,我给你两个点,请你算一算连接两点的折线长度(即沿折线走的路线长度)吧。
甜甜的好朋友蜜蜜发现上面的图还是有点规则的,于是他问甜甜:在你画的图中,我给你两个点,请你算一算连接两点的折线长度(即沿折线走的路线长度)吧。
  Input
 
  第一个数是正整数N(≤100)。代表数据的组数。
  
每组数据由四个非负整数组成x1,y1,x2,y2;所有的数都不会大于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;
	}
}
 
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号