|
@@ -22,6 +22,8 @@ var Cars []*Car
|
22
|
22
|
var Sched Scheduler
|
23
|
23
|
|
24
|
24
|
type Ride struct {
|
|
25
|
+ ID int
|
|
26
|
+
|
25
|
27
|
a, b, x, y, s, f int
|
26
|
28
|
|
27
|
29
|
used bool
|
|
@@ -41,7 +43,26 @@ type Car struct {
|
41
|
43
|
Y int
|
42
|
44
|
}
|
43
|
45
|
|
44
|
|
-func (c *Car) Update(r *Ride) {}
|
|
46
|
+func (c *Car) Update(r *Ride) {
|
|
47
|
+ c.moveTo(r.a, r.b)
|
|
48
|
+ c.moveTo(r.x, r.y)
|
|
49
|
+ c.Rides = append(c.Rides, r.ID)
|
|
50
|
+}
|
|
51
|
+
|
|
52
|
+func (c *Car) moveTo(x, y int) {
|
|
53
|
+ xdist := c.X - x
|
|
54
|
+ if xdist < 0 {
|
|
55
|
+ xdist = -xdist
|
|
56
|
+ }
|
|
57
|
+ ydist := c.Y - y
|
|
58
|
+ if ydist < 0 {
|
|
59
|
+ ydist = -ydist
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ c.Arrival += xdist + ydist
|
|
63
|
+ c.X = x
|
|
64
|
+ c.Y = y
|
|
65
|
+}
|
45
|
66
|
|
46
|
67
|
func Choose(c *Car) *Ride { return nil }
|
47
|
68
|
|
|
@@ -115,12 +136,13 @@ func main() {
|
115
|
136
|
|
116
|
137
|
for i := 0; i < N; i++ {
|
117
|
138
|
Rides = append(Rides, &Ride{
|
118
|
|
- a: readInt(),
|
119
|
|
- b: readInt(),
|
120
|
|
- x: readInt(),
|
121
|
|
- y: readInt(),
|
122
|
|
- s: readInt(),
|
123
|
|
- f: readInt(),
|
|
139
|
+ ID: i,
|
|
140
|
+ a: readInt(),
|
|
141
|
+ b: readInt(),
|
|
142
|
+ x: readInt(),
|
|
143
|
+ y: readInt(),
|
|
144
|
+ s: readInt(),
|
|
145
|
+ f: readInt(),
|
124
|
146
|
})
|
125
|
147
|
}
|
126
|
148
|
|