-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path270.go
66 lines (58 loc) · 1.1 KB
/
270.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// UVa 270 - Lining Up
package main
import (
"bufio"
"fmt"
"math"
"os"
)
type point struct{ x, y float64 }
func slope(p1, p2 point) [2]float64 {
if p1.x == p2.x {
return [2]float64{math.MaxFloat64, 0}
}
k := (p1.y - p2.y) / (p1.x - p2.x)
return [2]float64{k, -k*p1.x + p1.y}
}
func solve(points []point) int {
slopeMap := make(map[[2]float64]int)
for i, l := 0, len(points); i < l-1; i++ {
for j := i + 1; j < l; j++ {
slopeMap[slope(points[i], points[j])]++
}
}
var max int
for _, v := range slopeMap {
if v > max {
max = v
}
}
return max
}
func main() {
in, _ := os.Open("270.in")
defer in.Close()
out, _ := os.Create("270.out")
defer out.Close()
s := bufio.NewScanner(in)
s.Split(bufio.ScanLines)
var kase int
var x, y float64
var line string
s.Scan()
fmt.Sscanf(s.Text(), "%d", &kase)
for s.Scan(); kase > 0; kase-- {
var points []point
for s.Scan() {
if line = s.Text(); line == "" {
break
}
fmt.Sscanf(s.Text(), "%f%f", &x, &y)
points = append(points, point{x, y})
}
fmt.Fprintln(out, solve(points))
if kase > 1 {
fmt.Fprintln(out)
}
}
}