結果

問題 No.94 圏外です。(EASY)
ユーザー mizunomidorimizunomidori
提出日時 2016-07-04 01:28:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,943 bytes
コンパイル時間 702 ms
コンパイル使用メモリ 75,804 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 14:54:50
合計ジャッジ時間 1,800 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>

#define N_MAX 1000

using namespace std;

class union_find_tree
{
    private:
        int *par;
        int *rank;
    public:
        union_find_tree(int n);
        int root(int x);
        void unite(int x, int y);
        bool same(int x, int y);
};

union_find_tree::union_find_tree(int n)
{
    par = new int[n];
    rank = new int[n];
    for (int i = 0; i < n; i++) {
        par[i] = i;
        rank[i] = 0;
    }
}

int union_find_tree::root(int x)
{
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = root(par[x]);
    }
}

void union_find_tree::unite(int x, int y)
{
    x = root(x);
    y = root(y);
    if (x == y) {
        return;
    }
    if (rank[x] < rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rank[x] == rank[y]) {
            rank[x]++;
        }
    }
}

bool union_find_tree::same(int x, int y) {
    return root(x) == root(y);
}

int main(void)
{
    int N, X[N_MAX], Y[N_MAX];
    cin >> N;
    if (N == 0) {
        printf("1\n");
        return 0;
    }
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];
    }
    union_find_tree uft(N);
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int dX = X[i] - X[j], dY = Y[i] - Y[j];
            if (dX*dX + dY*dY <= 10*10) {
                uft.unite(i, j);
            }
        }
    }
    double d = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (uft.same(i, j)) {
                d = max(d, sqrt(pow(X[i] - X[j], 2) + pow(Y[i] - Y[j], 2)));
            }
        }
    }
    printf("%lf\n", d + 2);
    return 0;
}
0