-
Notifications
You must be signed in to change notification settings - Fork 27
/
10078.go
48 lines (41 loc) · 853 Bytes
/
10078.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
// UVa 10078 - The Art Gallery
package main
import (
"fmt"
"os"
)
type point struct{ x, y int }
func cross(p, p1, p2 point) int { return (p1.x-p.x)*(p2.y-p.y) - (p1.y-p.y)*(p2.x-p.x) }
func isConvex(points []point) bool {
points = append(points, points[:2]...)
var pre int
for i := 0; i < len(points)-2; i++ {
curr := cross(points[i], points[i+1], points[i+2])
if i > 0 && pre*curr < 0 {
return false
}
pre = curr
}
return true
}
func main() {
in, _ := os.Open("10078.in")
defer in.Close()
out, _ := os.Create("10078.out")
defer out.Close()
var n int
for {
if fmt.Fscanf(in, "%d", &n); n == 0 {
break
}
points := make([]point, n)
for i := range points {
fmt.Fscanf(in, "%d%d", &points[i].x, &points[i].y)
}
if isConvex(points) {
fmt.Fprintln(out, "No")
} else {
fmt.Fprintln(out, "Yes")
}
}
}