HDU 2001 (水)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2001

题目大意:两个点求距离

解题思路:

套基本公式 a = √(b2 + c2);

小数点后几位的表示方法,用std命名空间中常见的的流控制符,用到setprecision函数和<iomanip>头文件,fixed是非科学记数法的普通表示;

ax == pow(a, x);

pow(),sqrt()均在<math>里

代码:

#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
    double a, b, c, d;
    while(cin >> a >> b >> c >> d)
    {
        cout << fixed << setprecision(2) << sqrt((a-c)*(a-c) + (b-d)*(b-d)) << endl;
    }

}

 

原文地址:https://www.cnblogs.com/gerjcs/p/9356942.html