algorithm-dev

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub today2098/algorithm-dev

:heavy_check_mark: verify/aoj-ITP1_10_A-isqrt.test.cpp

Depends on

Code

#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/10/ITP1_10_A"

#define ERROR 1e-4

#include <iostream>

#include "../algorithm/Math/Algebra/square_root.hpp"

int main() {
    double x1, y1, x2, y2;
    std::cin >> x1 >> y1 >> x2 >> y2;

    auto tmp = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
    auto &&ans = algorithm::sqrt(tmp, 1e-8);
    printf("%.6f\n", ans);
}
#line 1 "verify/aoj-ITP1_10_A-isqrt.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/10/ITP1_10_A"

#define ERROR 1e-4

#include <iostream>

#line 1 "algorithm/Math/Algebra/square_root.hpp"



#include <cassert>
#include <cmath>

namespace algorithm {

// 平方根(ニュートン法).
constexpr double sqrt(double x, double eps = 1e-10) {
    assert(x >= 0.0);
    double res = 1.0;
    while(true) {
        double tmp = (x / res + res) / 2;
        if(std::abs(tmp - res) < eps) break;
        res = tmp;
    }
    return res;
}

}  // namespace algorithm


#line 8 "verify/aoj-ITP1_10_A-isqrt.test.cpp"

int main() {
    double x1, y1, x2, y2;
    std::cin >> x1 >> y1 >> x2 >> y2;

    auto tmp = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
    auto &&ans = algorithm::sqrt(tmp, 1e-8);
    printf("%.6f\n", ans);
}
Back to top page