結果
問題 | No.94 圏外です。(EASY) |
ユーザー |
|
提出日時 | 2014-12-07 20:46:25 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 9 ms / 5,000 ms |
コード長 | 2,413 bytes |
コンパイル時間 | 949 ms |
コンパイル使用メモリ | 98,680 KB |
実行使用メモリ | 7,680 KB |
最終ジャッジ日時 | 2024-06-26 07:20:52 |
合計ジャッジ時間 | 1,821 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#include <cstdio>#include <iostream>#include <sstream>#include <fstream>#include <iomanip>#include <algorithm>#include <cmath>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <set>#include <map>#include <bitset>#include <numeric>#include <limits>#include <climits>#include <cfloat>#include <functional>using namespace std;// Union-Find木class UnionFindTree{int n;vector<int> parent; // 親ノードvector<int> rank; // 木の高さの上限vector<int> num; // グループの要素数int find(int x){if(parent[x] == x)return x;return parent[x] = find(parent[x]);}public:UnionFindTree(int n0){ // コンストラクタn = n0;parent.resize(n);for(int i=0; i<n; ++i)parent[i] = i;rank.assign(n, 0);num.assign(n, 1);}void unite(int x, int y){ // xとyのグループを併合if((x = find(x)) != (y = find(y))){if(rank[x] < rank[y]){parent[x] = y;num[y] += num[x];}else{parent[y] = x;if(rank[x] == rank[y])++ rank[x];num[x] += num[y];}-- n;}}bool same(int x, int y){ // xとyのグループが同じかを調べるreturn find(x) == find(y);}int getNum(){ // グループの数を返すreturn n;}int getNum(int x){ // xのグループの要素数を返すreturn num[find(x)];}};int main(){int n;cin >> n;vector<int> x(n), y(n);for(int i=0; i<n; ++i)cin >> x[i] >> y[i];vector<vector<int> > dist(n, vector<int>(n));UnionFindTree uft(n);for(int i=0; i<n; ++i){for(int j=i; j<n; ++j){int dy = y[i] - y[j];int dx = x[i] - x[j];dist[i][j] = dy * dy + dx * dx;if(dist[i][j] <= 10 * 10)uft.unite(i, j);}}double ret = 1.0;for(int i=0; i<n; ++i){for(int j=i; j<n; ++j){if(uft.same(i, j))ret = max(ret, sqrt((double)dist[i][j]) + 2.0);}}printf("%.10f\n", ret);return 0;}