結果
| 問題 |
No.94 圏外です。(EASY)
|
| コンテスト | |
| ユーザー |
mizunomidori
|
| 提出日時 | 2016-07-04 01:28:47 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 1,943 bytes |
| コンパイル時間 | 629 ms |
| コンパイル使用メモリ | 81,828 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-26 07:59:14 |
| 合計ジャッジ時間 | 1,620 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#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;
}
mizunomidori