結果

問題 No.245 貫け!
ユーザー yuki2006yuki2006
提出日時 2015-07-17 21:39:05
言語 Go
(1.22.1)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 1,447 bytes
コンパイル時間 10,888 ms
コンパイル使用メモリ 218,776 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 02:35:47
合計ジャッジ時間 11,819 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 11 ms
5,376 KB
testcase_12 AC 26 ms
5,376 KB
testcase_13 AC 24 ms
5,376 KB
testcase_14 AC 25 ms
5,376 KB
testcase_15 AC 24 ms
5,376 KB
testcase_16 AC 24 ms
5,376 KB
testcase_17 AC 26 ms
5,376 KB
testcase_18 AC 24 ms
5,376 KB
testcase_19 AC 25 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

type Point struct {
	X int
	Y int
}
type Vector struct {
	X int
	Y int
}


type Line struct{
	A Point
	B Point
}

func vec(p1 Point, p2 Point) Vector {
	return Vector{p2.X - p1.X, p2.Y - p1.Y}
}
func cross(p1 Vector, p2 Vector) int {
	return p1.X * p2.Y - p1.Y * p2.X
}


func intersect(p1 Point, p2 Point, l Line) bool {
	return cross(vec(p1, p2), vec(p1, l.A))*cross(vec(p1, p2), vec(p1, l.B)) <= 0
}

func main() {

	var N int

	fmt.Scanf("%d", &N)

	var p = make([]Point, 2*N)
	var lines = make([]Line, N)

	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d %d %d", &p[2*i].X, &p[2*i].Y, &p[2*i+1].X, &p[2*i+1].Y)
		lines[i].A = p[2*i]
		lines[i].B = p[2*i+1]
	}
	mx := 0
	for i := 0; i < 2*N; i++ {
		for j := 0; j < 2*N; j++ {
			if p[i] == p[j] {
				continue
			}
			count := 0

			for k := 0; k < N; k+=1 {
				if intersect(p[i], p[j], lines[k]) {
					count+=1
				}
			}
			mx = max(mx, count)
		}
	}

	fmt.Println(mx)

}

var s = bufio.NewScanner(os.Stdin)

func next() string {
	s.Split(bufio.ScanWords)
	s.Scan()
	return s.Text()
}
func nextLine() string {
	s.Split(bufio.ScanLines)
	s.Scan()
	return s.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(next())
	if e != nil {
		panic(e)
	}
	return i
}
func nextLong() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}
0