-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path634.go
46 lines (40 loc) · 857 Bytes
/
634.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
// UVa 634 - Polygon
package main
import (
"fmt"
"os"
)
type point struct{ x, y int }
func solve(n int, p point, vertices []point) int {
var count int
for i, j := 0, n-1; i < n; i, j = i+1, i {
if (vertices[i].y-p.y)*(vertices[j].y-p.y) <= 0 &&
p.x-vertices[i].x < (vertices[j].x-vertices[i].x)*(p.y-vertices[i].y)/(vertices[j].y-vertices[i].y) {
count++
}
}
return count
}
func main() {
in, _ := os.Open("634.in")
defer in.Close()
out, _ := os.Create("634.out")
defer out.Close()
var n int
var p point
for {
if fmt.Fscanf(in, "%d", &n); n == 0 {
break
}
vertices := make([]point, n)
for i := range vertices {
fmt.Fscanf(in, "%d%d", &vertices[i].x, &vertices[i].y)
}
fmt.Fscanf(in, "%d%d", &p.x, &p.y)
if solve(n, p, vertices)%2 == 1 {
fmt.Fprintln(out, "T")
} else {
fmt.Fprintln(out, "F")
}
}
}