-
Notifications
You must be signed in to change notification settings - Fork 674
/
Copy pathp1429.go
73 lines (69 loc) · 1.32 KB
/
p1429.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"cmp"
. "fmt"
"io"
"math"
"slices"
)
// github.com/EndlessCheng/codeforces-go
func p1429(in io.Reader, out io.Writer) {
type vec struct{ x, y float64 }
merge := func(a, b []vec) []vec {
i, n := 0, len(a)
j, m := 0, len(b)
res := make([]vec, 0, n+m)
for {
if i == n {
return append(res, b[j:]...)
}
if j == m {
return append(res, a[i:]...)
}
if a[i].y < b[j].y {
res = append(res, a[i])
i++
} else {
res = append(res, b[j])
j++
}
}
}
var f func([]vec) float64
f = func(ps []vec) float64 {
n := len(ps)
if n <= 1 {
return math.MaxFloat64
}
m := n >> 1
x := ps[m].x
d := math.Min(f(ps[:m]), f(ps[m:]))
copy(ps, merge(ps[:m], ps[m:]))
checkPs := []vec{}
for _, pi := range ps {
if math.Abs(pi.x-x) > d+1e-8 {
continue
}
for j := len(checkPs) - 1; j >= 0; j-- {
pj := checkPs[j]
dy := pi.y - pj.y
if dy >= d {
break
}
dx := pi.x - pj.x
d = math.Min(d, math.Hypot(dx, dy))
}
checkPs = append(checkPs, pi)
}
return d
}
var n int
Fscan(in, &n)
ps := make([]vec, n)
for i := range ps {
Fscan(in, &ps[i].x, &ps[i].y)
}
slices.SortFunc(ps, func(a, b vec) int { return cmp.Compare(a.x, b.x) })
Fprintf(out, "%.4f", f(ps))
}
//func main() { p1429(bufio.NewReader(os.Stdin), os.Stdout) }