結果

問題 No.94 圏外です。(EASY)
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-02-18 21:09:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 3,055 bytes
コンパイル時間 1,429 ms
コンパイル使用メモリ 153,060 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 14:43:03
合計ジャッジ時間 2,504 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 4 ms
4,384 KB
testcase_09 AC 6 ms
4,384 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 6 ms
4,384 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 6 ms
4,384 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 7 ms
4,380 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    real EPS = 1e-8;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    struct Point {
        real x, y;
        Point() {}
        Point(real x, real y) : x(x), y(y) {}
        Point operator+(const Point& p) const { return Point(x + p.x, y + p.y); }
        Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); }
        Point operator*(real k) const { return Point(k * x, k * y); }
        Point operator/(real k) const { return Point(x / k, y / k); }
    };
    real dot(const Point& a, const Point& b) { return a.x * b.x + a.y * b.y; }
    real cross(const Point& a, const Point& b) { return a.x * b.y - a.y * b.x; }
    real norm(const Point& a) { return sqrt(dot(a, a)); }
    Point rot90(const Point& p) { return Point(-p.y, p.x); } // 反時計回りに90度回転 
    real angle(const Point& a) { return atan2(a.y, a.x); } // x軸を反時計回りに何ラジアン回転させれば点aに乗るか
    ostream& operator<<(ostream& os, const Point& p) { return os << "(" << p.x << "," << p.y << ")"; }
    istream& operator>>(istream& is, Point& p) { return is >> p.x >> p.y; }

    struct UnionFind {
        int N;
        vector<int> P;
        UnionFind(int N) : N(N) {
            P.clear(); P.resize(N, -1);
        }
        int root(int x) {
            if (P[x] == -1) return x;
            return P[x] = root(P[x]);
        }
        int query(int x, int y) {
            return root(x) == root(y);
        }
        void merge(int x, int y) {
            x = root(x); y = root(y);
            if (x == y) return;
            P[x] = y;
        }
    };

    int N;
    vector<Point> P;
    void input() {
        cin >> N;
        P.resize(N);
        cin >> P;
    }

    void solve() {
        real ans = 0;
        UnionFind uf(N);
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                const Point& a = P[i];
                const Point& b = P[j];
                if ( norm(a - b) < 10.0 + EPS ) {
                    uf.merge(i, j);
                }
            }
        }
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                const Point& a = P[i];
                const Point& b = P[j];
                if (uf.query(i, j)) {
                    ans = max(ans, norm(a - b));
                }
            }
        }
        if (N == 0) {
            cout << setprecision(12) << 1 << endl;
        } else {
            cout << setprecision(12) << ans + 2 << endl;
        }
    }
}

int main() {
    input(); solve();
    return 0;
}

0