-
Notifications
You must be signed in to change notification settings - Fork 0
/
14.go
51 lines (48 loc) · 1.31 KB
/
14.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
package main
import "fmt"
import "time"
func main() {
type robot struct {x, y, vx, vy int}
var xsize, ysize = 101, 103
var robots []robot
for {
var r robot
if n, _ := fmt.Scanf("p=%d,%d v=%d,%d", &r.x, &r.y, &r.vx, &r.vy); n < 4 { break }
robots = append(robots, r)
}
if len(robots) < 50 { xsize, ysize = 11, 7 } // example board size
for s := 1; ; s++ {
for i, _ := range robots {
var r = &robots[i]
r.x += r.vx
if r.x < 0 { r.x += xsize } else if r.x > xsize - 1 { r.x -= xsize }
r.y += r.vy
if r.y < 0 { r.y += ysize } else if r.y > ysize - 1 { r.y -= ysize }
}
var q1, q2, q3, q4 int
for _, r := range robots {
if r.x < xsize / 2 {
if r.y < ysize / 2 { q1++ } else if r.y > ysize / 2 { q3++ }
} else if r.x > xsize / 2 {
if r.y < ysize / 2 { q2++ } else if r.y > ysize / 2 { q4++ }
}
}
if s == 100 {
fmt.Println(q1 * q2 * q3 * q4)
}
if q1 > len(robots) / 2 || q2 > len(robots) / 2 || q3 > len(robots) / 2 || q4 > len(robots) / 2 {
for y := 0; y < ysize; y++ {
for x := 0; x < xsize; x++ {
var occupied = false
for _, e := range robots {
if e.x == x && e.y == y { occupied = true; break }
}
if occupied { fmt.Print("R") } else { fmt.Print(" ") }
}
fmt.Println()
}
fmt.Println("second", s)
time.Sleep(time.Second)
}
}
}