CSES - Aalto Competitive Programming 2024 - wk10 - Mon - Results
Submission details
Task:6G network
Sender:arnxxau
Submission time:2024-11-11 17:41:49 +0200
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'double distance(int, int, int, int)':
input/code.cpp:11:17: error: 'pow' was not declared in this scope
   11 |     return sqrt(pow((x1 - x2), 2) +
      |                 ^~~
input/code.cpp:11:12: error: 'sqrt' was not declared in this scope
   11 |     return sqrt(pow((x1 - x2), 2) +
      |            ^~~~
input/code.cpp: In function 'int main()':
input/code.cpp:47:9: warning: unused variable 'K' [-Wunused-variable]
   47 |     int K = 1;
      |         ^

Code


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <vector>
using namespace std;

double distance(int x1, int y1, int x2, int y2) {
    return sqrt(pow((x1 - x2), 2) +
                pow((y1 - y2), 2));
}

double mindist(
    vector<vector<double> >& points,
    vector<double> target) {
    vector<vector<double> > pts;
    int n = points.size();

    double mind = numeric_limits<double>::max();

    for (int i = 0; i < n; i++) {
        double dist = distance(points[i][0], points[i][1],
                               target[0], target[1]);

        if (dist != 0) mind = min(mind, dist);
    }

    // cout << mind << endl;
    return mind;
}

int main() {
    int n;
    cin >> n;
    vector<vector<double> > points(n);

    for (int i = 0; i < n; i++) {
        vector<double> point = {1, 1};
        cin >> point[0];
        cin >> point[1];
        points[i] = point;
    }

    vector<double> target = {0, 1};
    int K = 1;

    double maxd = numeric_limits<double>::min();
    for (int i = 0; i < n; i++) {
        vector<double> target = points[i];
        maxd = max(mindist(points, target), maxd);
    }

    cout << setprecision(25) << maxd << endl;
}