Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,6 @@ object Combinator { | |
}} | ||
} | ||
|
||
object Permutator { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//package misc.codejam.sra | ||
// | ||
//import scala.collection.mutable.ListBuffer | ||
// | ||
//import misc.codejam.common.CodejamCaseReader | ||
//import misc.codejam.common.Headline | ||
//import misc.codejam.sra.LevelInfo | ||
//import misc.codejam.srb.CellInfo | ||
// | ||
//class CaveInfoReader(resourcePath: String) | ||
// extends CodejamCaseReader[CellInfo](resourcePath) | ||
// with Headline { | ||
// | ||
// // chunk 처리용 type 선언 | ||
// type ChunkType = List[List[CellInfo]] | ||
// | ||
// override val headLine = lines.next | ||
// | ||
// override def readNext(): List[LevelInfo] = { | ||
//// val totalLevel = lines.next.toInt | ||
//// require(totalLevel > 0) | ||
//// | ||
//// val levelInfos:ListBuffer[LevelInfo] = ListBuffer(); | ||
//// | ||
//// for (idx <- 1 to totalLevel) { | ||
//// val Array(oneStar, twoStar) = lines.next.split(" ") | ||
//// // val levelInfo = new CellInfo(idx, oneStar.toInt, twoStar.toInt, StarLevel.NotFished) | ||
//// // levelInfos+= levelInfo | ||
//// } | ||
//// levelInfos.toList | ||
// Nil | ||
// } | ||
// | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package misc.codejam.srb | ||
|
||
case class CellInfo(val ceiling:Int, val floor:Int, var isDone:Boolean) { | ||
def isMovable(that:CellInfo):Boolean = { | ||
if (that.ceiling - that.floor < 50) { | ||
false | ||
} else { | ||
val diff1 = Math.abs(this.ceiling - that.floor); | ||
val diff2 = Math.abs(this.floor - that.ceiling); | ||
(Math.min(diff1,diff2) >= 50) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package misc.codejam.srb | ||
import scala.collection.mutable.ListBuffer | ||
|
||
import misc.codejam.srb.CellInfo | ||
|
||
object TideInTideOut { | ||
val cave:Cave = null; | ||
|
||
val direction = cave.getMovableDirection(); | ||
|
||
val (second, nextCave) = cave.moveTo(direction(0)) | ||
|
||
|
||
} | ||
class Cave(val pos:(Int,Int), val height: Int, val cave: List[List[CellInfo]]) { | ||
type Second = Int | ||
type Height = Int | ||
|
||
val (curX, curY) = pos | ||
val curCell = cave(curY)(curX) | ||
|
||
def getMovableDirection():List[(Int,Int)] = { | ||
def checkMovable(x:Int, y:Int):Boolean ={ | ||
if (x> -1 && y> -1 && y< cave.size && x < cave(0).size) { | ||
val to = cave(y)(x) | ||
(!to.isDone) && (curCell.isMovable (to)) | ||
} else { | ||
false | ||
} | ||
} | ||
val movable:ListBuffer[(Int,Int)] = new ListBuffer(); | ||
// up | ||
if (checkMovable(curX, curY-1)) movable+=((curX, curY-1)) | ||
// down | ||
if (checkMovable(curX, curY+1)) movable+=((curX, curY+1)) | ||
// left | ||
if (checkMovable(curX-1, curY)) movable+=((curX-1, curY)) | ||
// right | ||
if (checkMovable(curX+1, curY)) movable+=((curX+1, curY)) | ||
|
||
movable.toList | ||
} | ||
|
||
def moveTo(pos:(Int,Int)):(Second, Cave) = { | ||
val (x,y) = pos | ||
curCell.isDone = true | ||
val timeToMove = getTimeToMove(cave(y)(x)) | ||
val nextHeight = height - timeToMove * 10 | ||
(timeToMove, new Cave(pos, nextHeight, cave)) | ||
} | ||
|
||
def getTimeToMove( to: CellInfo):Second = { | ||
var currentHeight = height; | ||
|
||
// wait time | ||
val lowerCeiling = Math.min(to.ceiling, curCell.ceiling); | ||
var waitSec = (currentHeight - (lowerCeiling - 50)) / 10 | ||
if (waitSec < 0) waitSec = 0 | ||
else { | ||
currentHeight = Math.min(to.ceiling, curCell.ceiling) - 50 | ||
} | ||
|
||
if (currentHeight - curCell.floor > 20) { | ||
// water | ||
waitSec + 1 | ||
} else { | ||
// lands | ||
waitSec + 10 | ||
} | ||
} | ||
} | ||
|
||
object Test extends App { | ||
// Console.println(TideInTideOut.getTimeToMove(150, CellInfo(200, 0), CellInfo(100, 0))); | ||
// Console.println(TideInTideOut.getTimeToMove(150, CellInfo(200, 0), CellInfo(100, 80))); | ||
// Console.println(TideInTideOut.getTimeToMove(100, CellInfo(200, 100), CellInfo(140, 0))); | ||
// Console.println(TideInTideOut.getTimeToMove(150, CellInfo(300, 100), CellInfo(170, 0))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package misc.codejam.srb | ||
|
||
class CaveSpec extends { | ||
|
||
} |