結果
問題 | No.245 貫け! |
ユーザー |
|
提出日時 | 2015-07-18 12:30:17 |
言語 | Scala(Beta) (3.6.2) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 6,140 bytes |
コンパイル時間 | 7,415 ms |
コンパイル使用メモリ | 238,960 KB |
最終ジャッジ日時 | 2024-11-14 19:06:26 |
合計ジャッジ時間 | 7,766 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
[31m[31m-- [E100] Syntax Error: Main.scala:26:34 ---------------------------------------[0m[0m [31m26 |[0m [33mdef[0m [36mabs[0m() = Math.sqrt([33mthis[0m.norm) [31m[31m |[0m ^^^^^^^^^[0m [31m |[0m [33mmethod[0m [35mnorm[0m in [33mclass[0m [35mPoint[0m must be called with () argument [31m |[0m [31m |[0m longer explanation available when compiling with `-explain` [31m[31m-- [E100] Syntax Error: Main.scala:28:29 ---------------------------------------[0m[0m [31m28 |[0m [33mdef[0m [36mlengthAsVector[0m() = abs [31m[31m |[0m ^^^[0m [31m |[0m [33mmethod[0m [35mabs[0m in [33mclass[0m [35mPoint[0m must be called with () argument [31m |[0m [31m |[0m longer explanation available when compiling with `-explain` [31m[31m-- [E100] Syntax Error: Main.scala:27:48 ---------------------------------------[0m[0m [31m27 |[0m [33mdef[0m [36mdistanceTo[0m([36mthat[0m: [35mPoint[0m) = (that-[33mthis[0m).lengthAsVector [31m[31m |[0m ^^^^^^^^^^^^^^^^^^^^^^^^^^[0m [31m |[0m [33mmethod[0m [35mlengthAsVector[0m in [33mclass[0m [35mPoint[0m must be called with () argument [31m |[0m [31m |[0m longer explanation available when compiling with `-explain` [31m[31m-- [E100] Syntax Error: Main.scala:117:83 --------------------------------------[0m[0m [31m117 |[0m [33mdef[0m [36mdistanceTo[0m([36mthat[0m: [35mPoint[0m) = Math.abs(((a-that) cross (b-that)) / (a-b).abs) [31m[31m |[0m ^^^^^^^^^[0m [31m |[0m [33mmethod[0m [35mabs[0m in [33mclass[0m [35mPoint[0m must be called with () argument [31m |[0m [31m |[0m longer explanation available when compiling with `-explain` [33m[33m-- Warning: Main.scala:112:55 ---------
ソースコード
import scala.io.StdIn.readLineimport scala.collection.mutable.PriorityQueueimport scala.annotation.tailrec// PriorityQueue[Long]()(scala.math.Ordering.Long.reverse)package net.pushl {package number {// Prime (Prime.scala)// Number (Number.scala)}package string {// RollingHash (RollingHash.scala)}object EnRich {implicit class AString(val self: String) extends AnyVal {def splitToIntArray = self.split(" ").map(_.toInt)}}package geometry {// can be used as vector from zero pointclass Point(val y: Double, val x: Double) extends Ordered[Point] {// normally, Euclidean norm is abs, but it has high cost.val EPS = 1e-7 // TODO: make it private finaldef norm() = x*x + y*ydef abs() = Math.sqrt(this.norm)def distanceTo(that: Point) = (that-this).lengthAsVectordef lengthAsVector() = abs// rotate by theta (-pi,+pi)// TODO: validate rotatedef rotate(theta: Double) = {val cos_theta = Math.cos(theta)val sin_theta = Math.sin(theta)Point(x*cos_theta-y*sin_theta, x*sin_theta+y*cos_theta)}// TODO: validate these.// 内積: a・b = |a||b| cosθ// = ax*bx + ay*bydef dot(that: Point) =this.x*that.x + this.y+that.y// 外積(の大きさ) |a x b| = |a||b|sinθ// 外積はa から bへの右ねじの進む向きへのベクトル(三次元)def cross(that: Point) =this.x*that.y - this.y*that.x// FIXME: it is square area.def compare(that: Point) : Int = {val xdiff = Math.abs(this.x-that.x)val ydiff = Math.abs(this.y-that.y)if(xdiff <= EPS && ydiff <= EPS) 0else if(xdiff <= EPS && this.y < that.y) -1else if(xdiff <= EPS && this.y > that.y) +1else if(this.x < that.x) -1else +1}def +(that: Point) = Point(this.y+that.y,this.x+that.x)def -(that: Point) = this + (-that)def unary_+ = thisdef unary_- = Point(-this.y,-this.x)def /(that: Double)= this*(1/that)def *(that: Double)= Point(this.y*that,this.x*that)def canEqual(that: Any) = that.isInstanceOf[Point]override def equals(that: Any) = that match {case that: Point => that.canEqual(this) && (this.compare(that) == 0)case _ => false}override def toString() = s"($y, $x)"// TODO: validate hashcode.override def hashCode() = {val prime = 41val ax = Math.round(x+EPS) min Math.round(x-EPS)val ay = Math.round(y+EPS) min Math.round(y-EPS)prime * ax.hashCode + ay.hashCode}}object Point {def zero() = this(0,0)def apply(y: Double, x: Double) = new Point(y, x)}class Segment(val a: Point, val b: Point) {val EPS = 1e-7 // TODO: make it private final// TODO: test this// def isIntersected(that: Segment) = {// val this_a_x = a.x// val this_b_x = b.x// val this_upper_y = (a.y) max (b.y)// val this_lower_y = (a.y) min (b.y)// val that_a_x = that.a.x// val that_b_x = that.b.x// val that_upper_y = (that.a.y) max (that.b.y)// val that_lower_y = (that.a.y) min (that.b.y)// val no_chance = (this_b_x + EPS < that_a_x) ||// (that_b_x + EPS < this_a_x) ||// (that_upper_y + EPS < this_lower_y) ||// (this_upper_y + EPS < that_lower_y)// !no_chance &&// (((b-a) cross (that.a-a)) *// ((b-a) cross (that.b-a)) < EPS) &&// (((that.b-that.a) cross (a -that.a)) *// ((that.b-that.a) cross (b-that.a)) < EPS)// }override def toString() = s"S: $a -- $b"}object Segment {def apply(p1: Point, p2: Point) = new Segment(p1,p2)}class Line(val a: Point, val b: Point) {val EPS = 1e-7def isParallelTo(that: Line) = Math.abs((a-b) cross (that.a - that.b)) < EPSdef isIntersectedTo(that: Line) = !isParallelTo(that)def isIntersectedTo(that: Segment) = onThisLine(that.a) || onThisLine(that.b) ||(toClockWise(that.a) != toClockWise(that.b))def distanceTo(that: Point) = Math.abs(((a-that) cross (b-that)) / (a-b).abs)def onThisLine(that : Point) = distanceTo(that) < EPSdef toClockWise(that : Point) = if(onThisLine(that))sys.error("Before clockwise, check on this line")else((b-that) cross (a-that)) > 0override def toString() = s"L:-- $a -- $b --"}object Line {def apply(p1: Point, p2: Point) = if(p1 == p2)sys.error("Start and end of Line should be different")elsenew Line(p1,p2)}}}import net.pushl.EnRich._import net.pushl.geometry._object Main {def solve(segments: Vector[Segment]) : Int = {segments.flatMap((s1) =>segments.flatMap((s2) => {val cand = List(s1.a,s1.b,s2.a,s2.b)cand.flatMap((c1) =>cand.map((c2) =>if(c1 == c2) 0else segments.count(Line(c1,c2).isIntersectedTo(_))))})).max}def main(args : Array[String]) : Unit = {val n = readLine.toIntval segments = (1 to n).map(_ => {val (a,b,c,d) = {val abcd = readLine.splitToIntArray(abcd(0),abcd(1),abcd(2),abcd(3))}Segment(Point(a,b),Point(c,d))}).toVectorprintln(solve(segments))}}