結果

問題 No.94 圏外です。(EASY)
ユーザー fmhrfmhr
提出日時 2016-07-25 12:21:56
言語 Go
(1.22.1)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 1,659 bytes
コンパイル時間 11,663 ms
コンパイル使用メモリ 209,976 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 14:55:33
合計ジャッジ時間 12,604 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

import (
	"fmt"
	"math"
)

type xy struct {
	x int
	y int
}

func isLink(a, b, c, d int) bool {
	return 100 >= (c-a)*(c-a)+(d-b)*(d-b)
}

func distance(a, b, c, d int)float64{
	x := math.Sqrt(float64((c-a)*(c-a)+(b-d)*(b-d)))
	return x
}

func main() {
	var N int
	fmt.Scan(&N)
	repeater := make([]xy, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&repeater[i].x, &repeater[i].y)
	}
	uf := NewUnionFind(N)
	for i := 0; i < N; i++ {
		for j := i; j < N; j++ {
			if isLink(repeater[i].x, repeater[i].y, repeater[j].x, repeater[j].y) {
				uf.Unit(i, j)
			}
		}
	}
	ans := 1.0
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if uf.Same(i,j){
				ans = max(ans,2 + distance(repeater[i].x,repeater[i].y,repeater[j].x,repeater[j].y))
			}
		}
	}
	fmt.Println(ans)
}

func max(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

type UnionFind struct {
	par    []int // 親
	weight []int // 重み
	count  int   // 要素数
}

func NewUnionFind(count int) *UnionFind {
	par := make([]int, count)
	weight := make([]int, count)
	for i := 0; i < count; i++ {
		par[i] = i
		weight[i] = 1
	}
	return &UnionFind{par: par, weight: weight, count: count}
}

func (uf *UnionFind) Find(x int) int {
	if uf.par[x] == x {
		return x
	} else {
		uf.par[x] = uf.par[uf.par[x]]
		return uf.Find(uf.par[x])
	}
}

func (uf *UnionFind) Unit(x, y int) {
	x = uf.Find(x)
	y = uf.Find(y)
	if x == y {
		return
	}
	if uf.weight[x] > uf.weight[y] {
		x, y = y, x
	}
	uf.par[x] = y
	uf.weight[y] += uf.weight[x]
}

func (uf *UnionFind) Same(x, y int) bool {
	return uf.Find(x) == uf.Find(y)
}

func (uf UnionFind) test() {
	fmt.Println(uf.weight)
}
0