답안 #902531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
902531 2024-01-10T15:12:54 Z tz74 Mobile (BOI12_mobile) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

using i64 = long long;
using f64 = double;

f64 dist(f64 a, f64 b, f64 c, f64 d) {
    return sqrt((c - a) * (c - a) + (d - b) * (d - b));
}

int main(void) {
    i64 N_tmp, L; cin >> N_tmp >> L;
    vector<pair<i64, i64> > towers;
    for (int i = 0; i < N_tmp; i++) {
        pair<i64, i64> p;
        cin >> p.first >> p.second;

        // printf("p: %lld, %lld\n", p.first, p.second);

        if (i == 0 || towers.back().first != p.first) {
            towers.push_back(p);
        } else {
            towers.pop_back();
        }
    }

    f64 max_dist = 0;
    i64 N = towers.size();

    for (int i = 0, j = 1; i < N - 1 && j < N; i++, j++) {
        f64 P1_x = towers[i].first;
        f64 P1_y = towers[i].second;

        f64 P2_x = towers[j].first;
        f64 P2_y = towers[j].second;

        f64 x = (P2_x * P2_x - P1_x * P1_x + P2_y * P2_y - P1_y * P1_y) / (2 * (P2_x - P1_x));
        max_dist = max(max_dist, dist(P1_x, P1_y, x, 0));
    }

    // then try two endpoints
    max_dist = max(max_dist, dist(towers[0].first, towers[0].second, 0, 0));
    if (L >= towers[N - 1].first) {
        max_dist = max(max_dist, dist(towers[N - 1].first, towers[N - 1].second, 0, N));
    }

    cout << setprecision(10);
    cout << max_dist << endl;
}

Compilation message

mobile.cpp: In function 'f64 dist(f64, f64, f64, f64)':
mobile.cpp:11:12: error: 'sqrt' was not declared in this scope
   11 |     return sqrt((c - a) * (c - a) + (d - b) * (d - b));
      |            ^~~~