hdu 2001 計算兩點間的距離
計算兩點間的距離
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 395053 Accepted Submission(s): 133339
Problem Description
輸入兩點坐標(X1,Y1),(X2,Y2),計算并輸出兩點間的距離。
Input
輸入數(shù)據(jù)有多組,每組占一行,由4個實數(shù)組成,分別表示x1,y1,x2,y2,數(shù)據(jù)之間用空格隔開。
Output
對于每組輸入數(shù)據(jù),輸出一行,結(jié)果保留兩位小數(shù)。
Sample Input
0 0 0 1
0 1 1 0
Sample Output
1.00
1.41

代碼:
#include<stdio.h>
#include<math.h>
int main()
{
double x1,y1,x2,y2,s;
while(scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2) != EOF)
{
s=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
printf("%.2lf\n",s);
}
return 0;
}
評論
圖片
表情
