hdu 2001 计算两点间的距离 sqrt的应用,浮点数 的精度运用
2017-02-07 13:06
302 查看
计算两点间的距离
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 202162 Accepted Submission(s): 70437
Problem Description
输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。
Input
输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。
Output
对于每组输入数据,输出一行,结果保留两位小数。
Sample Input
0 0 0 1
0 1 1 0
Sample Output
1.00
1.41
本题思路:
假设l为两点之间的长度
l=sqrt((x1-x2)(x1-x2)+(y1-y2)(y1-y2))
sqrt是求算数平方根的函数,头文件为 #include< math.h >
例如:8==sqrt(64)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 202162 Accepted Submission(s): 70437
Problem Description
输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。
Input
输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。
Output
对于每组输入数据,输出一行,结果保留两位小数。
Sample Input
0 0 0 1
0 1 1 0
Sample Output
1.00
1.41
本题思路:
假设l为两点之间的长度
l=sqrt((x1-x2)(x1-x2)+(y1-y2)(y1-y2))
sqrt是求算数平方根的函数,头文件为 #include< math.h >
例如:8==sqrt(64)
#include <stdio.h> #include <stdlib.h> #include<math.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { double a,b,c,d; double l; while(scanf("%lf%lf%lf%lf",&a,&b,&c,&d)!=EOF) { l=sqrt((d-b)*(d-b)+(c-a)*(c-a)); printf("%.2lf\n",l); } return 0; }
相关文章推荐
- HDU_ACM-2001 计算两点间的距离
- HDU 2001 计算两点间的距离
- hdu 2001 计算两点间的距离
- 计算两点间的距离,hdu-2001
- HDU 2001 - 计算两点间的距离
- HDU-2001 计算两点之间的距离
- hdu 2001 java/c++ 计算两点间的距离
- HDU_2001——计算两点之间的距离
- HDU 2001 计算两点间的距离 解题报告
- HDU-2001 计算两点间的距离
- HDU 2001 计算两点间的距离
- hdu 2001计算两点间的距离
- hdu 2001 计算两点间的距离
- HDU 2001 计算两点间的距离
- hdu_2001_计算两点间的距离_解题报告
- hdu_2001_计算两点间的距离_水之
- HDU 2001 计算两点间的距离
- 杭电hdu 2001 计算两点间的距离
- HDU 2001 计算两点间的距离
- 杭电hdu2001 计算两点间的距离 每行4个数 C++