-
Notifications
You must be signed in to change notification settings - Fork 27
/
460.go
52 lines (45 loc) · 1.15 KB
/
460.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
52
// UVa 460 - Overlapping Rectangles
package main
import (
"fmt"
"os"
)
type (
point struct{ x, y int }
window struct{ p1, p2 point }
)
func in(p point, w window) bool { return p.x > w.p1.x && p.x < w.p2.x && p.y > w.p1.y && p.y < w.p2.y }
func solve(w1, w2 window) *window {
switch {
case in(w1.p1, w2):
return &window{w1.p1, w2.p2}
case in(w1.p2, w2):
return &window{w2.p1, w1.p2}
case in(point{w1.p1.x, w1.p2.y}, w2):
return &window{point{w1.p1.x, w2.p1.y}, point{w2.p2.x, w1.p2.y}}
case in(point{w1.p2.x, w1.p1.y}, w2):
return &window{point{w2.p1.x, w1.p1.y}, point{w1.p2.x, w2.p2.y}}
default:
return nil
}
}
func main() {
in, _ := os.Open("460.in")
defer in.Close()
out, _ := os.Create("460.out")
defer out.Close()
var kase int
var w1, w2 window
for fmt.Fscanf(in, "%d", &kase); kase > 0; kase-- {
fmt.Fscanf(in, "\n%d%d%d%d", &w1.p1.x, &w1.p1.y, &w1.p2.x, &w1.p2.y)
fmt.Fscanf(in, "%d%d%d%d", &w2.p1.x, &w2.p1.y, &w2.p2.x, &w2.p2.y)
if w := solve(w1, w2); w == nil {
fmt.Fprintln(out, "No Overlap")
} else {
fmt.Fprintf(out, "%d %d %d %d\n", w.p1.x, w.p1.y, w.p2.x, w.p2.y)
}
if kase > 1 {
fmt.Fprintln(out)
}
}
}