-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path10589.go
49 lines (42 loc) · 901 Bytes
/
10589.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
// UVa 10589 - Area
package main
import (
"fmt"
"os"
)
type point struct{ x, y float64 }
func distanceGreaterThan(p1, p2 point, a float64) bool {
return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) > a*a
}
func solve(a float64, points []point) float64 {
corners := []point{{0, 0}, {0, a}, {a, 0}, {a, a}}
var m int
here:
for _, p := range points {
for _, c := range corners {
if distanceGreaterThan(p, c, a) {
continue here
}
}
m++
}
return float64(m) * a * a / float64(len(points))
}
func main() {
in, _ := os.Open("10589.in")
defer in.Close()
out, _ := os.Create("10589.out")
defer out.Close()
var n int
var a float64
for {
if fmt.Fscanf(in, "%d%f", &n, &a); n == 0 && a == 0 {
break
}
points := make([]point, n)
for i := range points {
fmt.Fscanf(in, "%f%f", &points[i].x, &points[i].y)
}
fmt.Fprintf(out, "%.5f\n", solve(a, points))
}
}