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
|
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
type vector struct {
x, y int
}
func main() {
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
line := scanner.Text()
elts := strings.Split(line, "..")
eltsx1 := strings.Split(elts[0], "=")
x1, _ := strconv.Atoi(eltsx1[1])
eltsx2 := strings.Split(elts[1], ",")
x2, _ := strconv.Atoi(eltsx2[0])
eltsy1 := strings.Split(elts[1], "=")
y1, _ := strconv.Atoi(eltsy1[1])
y2, _ := strconv.Atoi(elts[2])
// We need to calculate which steps and horizontal speeds can hit the target box
x := 0
vx := 0 // its a vx max more than a vx
i := 1
for {
if x+vx+1 <= x2 {
vx += 1
x += vx
i++
} else {
break
}
}
hmax := 0
for nextVy := 0; nextVy < 10000; nextVy++ {
y := 0
vy := nextVy
tmpHmax := 0
j := 0
for {
if y+vy >= y1 {
y += vy
vy--
j++
} else {
break
}
if tmpHmax < y {
tmpHmax = y
}
}
if y >= y1 && y <= y2 && hmax < tmpHmax {
hmax = tmpHmax
fmt.Printf("h=%d, y=%d, vy=%d, j=%d\n", hmax, y, nextVy, j)
}
}
fmt.Printf("x1=%d, x2=%d, y1=%d, y2=%d\n", x1, x2, y1, y2)
fmt.Printf("i=%d, x=%d, vx=%d\n", i, x, vx)
fmt.Println(hmax)
}
|