-
Notifications
You must be signed in to change notification settings - Fork 0
[Week3] 안찬우 : 킹, 랜선 자르기, 크로스워드, 단풍잎이야기 #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,44 @@ | ||
package `3week`.acw | ||
|
||
class 단풍잎이야기{ | ||
lateinit var quests:Array<Array<Int>> | ||
lateinit var comb:Array<Boolean> | ||
private var answer=0 | ||
|
||
private fun makeComb(arr:MutableList<Int>, targetNum:Int, count:Int, start:Int){ | ||
if(count==targetNum){ | ||
|
||
for(i in 1 until 2*targetNum+1){ | ||
if(comb[i]){ | ||
arr.add(i) | ||
} | ||
} | ||
answer=answer.coerceAtLeast(quests.count{quest->arr.containsAll(quest.toList())}) | ||
|
||
arr.clear() | ||
return | ||
} | ||
|
||
for(i in start .. 2*targetNum){ | ||
comb[i]=true | ||
makeComb(arr,targetNum,count+1,i+1) | ||
comb[i]=false | ||
} | ||
} | ||
|
||
fun solution(){ | ||
val (n,m)=readln().split(" ").map{it.toInt()} | ||
quests=Array(m){readln().split(" ").map{it.toInt()}.toTypedArray()} | ||
comb=Array(2*n+1){false } | ||
|
||
makeComb(mutableListOf(),n,0,1) | ||
ChanwooAn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
println(answer) | ||
|
||
|
||
} | ||
} | ||
fun main() { | ||
val sol = 단풍잎이야기() | ||
sol.solution() | ||
} |
This file contains hidden or 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,47 @@ | ||
package `3week`.acw | ||
import java.util.PriorityQueue | ||
|
||
class 랜선자르기 { | ||
var answer = 0L | ||
lateinit var test : PriorityQueue<Long> | ||
|
||
private fun binarySearch(start: Long, end: Long, targetNum: Int) { | ||
|
||
if (start > end) { | ||
return | ||
} | ||
val now = ((start + end) / 2) | ||
val count = test.sumOf { it / now } | ||
|
||
if (count < targetNum) { | ||
binarySearch(start, now - 1, targetNum) | ||
//작을 땐 더 작은 수로 계산해보기 | ||
} else { | ||
answer = answer.coerceAtLeast(now) | ||
binarySearch(now + 1, end, targetNum) | ||
//크면 더 큰 수 찾아보기 | ||
} | ||
|
||
} | ||
|
||
fun solution() { | ||
val (K, N) = readln().split(" ").map { it.toInt() } | ||
|
||
test=PriorityQueue<Long>().apply{ | ||
addAll(Array(K){ readln().toLong() }) | ||
} | ||
|
||
binarySearch(1, test.last(), N) | ||
|
||
println(answer) | ||
|
||
|
||
} | ||
} | ||
|
||
fun main() { | ||
val sol = 랜선자르기() | ||
sol.solution() | ||
} | ||
|
||
|
This file contains hidden or 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,80 @@ | ||
package `3week`.acw | ||
import java.util.PriorityQueue | ||
|
||
|
||
class 크로스워드{ | ||
lateinit var puzzle: Array<String> | ||
var row=0 | ||
var column=0 | ||
|
||
private val direction = listOf( | ||
Pair(0, -1), | ||
Pair(0, 1), | ||
Pair(1, 0), | ||
Pair(-1, 0) | ||
) | ||
data class Pos(val y: Int,val x: Int) | ||
|
||
var words = PriorityQueue<String>() | ||
|
||
fun isIsolate(y:Int,x:Int):Boolean{ | ||
for(i in 0 until 4){ | ||
val nPos= Pos(y+direction[i].first,x+direction[i].second) | ||
|
||
if(nPos.y<0 || nPos.x<0 || nPos.y>=column ||nPos.x>=row){ | ||
continue | ||
} | ||
|
||
if(puzzle[nPos.y][nPos.x] !in 'a'..'z'){ | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
fun solution() { | ||
readln().split(" ").let{ (c,r) -> | ||
row=r.toInt() | ||
column=c.toInt() | ||
} | ||
puzzle = Array(column){ readln() } | ||
|
||
|
||
repeat(column){ | ||
puzzle[it].split("#").map { | ||
ChanwooAn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if(it.length>1){ | ||
words.add(it) | ||
} | ||
} | ||
|
||
}//가로 | ||
|
||
repeat(row){ | ||
var word="" | ||
for(i in 0 until column){ | ||
word+=puzzle[i][it] | ||
} | ||
word.split("#").map { | ||
if(it.length>1){ | ||
words.add(it) | ||
} | ||
} | ||
}//세로 | ||
|
||
for(i in 0 until column){ | ||
for(j in 0 until row){ | ||
isIsolate(i,j) | ||
} | ||
} | ||
|
||
|
||
println(words.first()) | ||
|
||
} | ||
} | ||
fun main(){ | ||
val sol = 크로스워드() | ||
sol.solution() | ||
} | ||
|
This file contains hidden or 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,97 @@ | ||
package `3week`.acw | ||
|
||
const val king=3 | ||
const val stone=2 | ||
class 킹{ | ||
lateinit var input:List<String> | ||
var chessMap=Array(8){Array(8){0} } | ||
|
||
val direction= hashMapOf<String,Pair<Int,Int>>( | ||
Pair("R",Pair(0,1)), | ||
Pair("L",Pair(0,-1)), | ||
Pair("B",Pair(1,0)), | ||
Pair("T",Pair(-1,0)), | ||
Pair("RT",Pair(-1,1)), | ||
Pair("LT",Pair(-1,-1)), | ||
Pair("RB",Pair(1,1)), | ||
Pair("LB",Pair(1,-1)) | ||
) | ||
ChanwooAn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
fun validate(y:Int,x:Int):Boolean{ | ||
return !(y<0 || x<0 || y>7 || x>7) | ||
} | ||
|
||
fun solution(){ | ||
input=readln().split(" ") | ||
|
||
var kingX=input[0][0]-'A' | ||
var kingY=8-input[0][1].digitToInt() | ||
|
||
var stoneX=input[1][0]-'A' | ||
var stoneY=8-input[1][1].digitToInt() | ||
ChanwooAn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
val N=input[2].toInt() | ||
|
||
chessMap[kingY][kingX]=king | ||
//king | ||
|
||
chessMap[stoneY][stoneX]=stone | ||
//stone | ||
|
||
for( i in 0 until N){ | ||
val mv=readln() | ||
|
||
val ny=kingY+direction[mv]!!.first | ||
val nx=kingX+direction[mv]!!.second | ||
if(!validate(ny,nx)){ | ||
continue | ||
}//유효성 check | ||
|
||
if(chessMap[ny][nx]==stone){ | ||
val nsy=stoneY+direction[mv]!!.first | ||
val nsx=stoneX+direction[mv]!!.second | ||
ChanwooAn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if(!validate(nsy,nsx)){ | ||
continue | ||
}//돌이 자리를 비켜주지 못할 때 | ||
else{ | ||
chessMap[stoneY][stoneX]=0 | ||
chessMap[kingY][kingX]=0 | ||
|
||
chessMap[nsy][nsx]=stone | ||
chessMap[ny][nx]=king | ||
|
||
kingY=ny | ||
kingX=nx | ||
|
||
stoneY=nsy | ||
stoneX=nsx | ||
//이동시켜주기 | ||
|
||
continue | ||
} | ||
|
||
}//가는 자리에 돌이 있을 때 | ||
|
||
|
||
chessMap[kingY][kingX]=0 | ||
chessMap[ny][nx]=king | ||
kingY=ny | ||
kingX=nx | ||
//아무문제 없으면 king만 이동 | ||
|
||
} | ||
|
||
|
||
|
||
println("${(kingX+'A'.toInt()).toChar()}${8-kingY}\n${(stoneX+'A'.toInt()).toChar()}${8-stoneY}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 출력에 개행 포함해서 out 연산이 한번인건 좋아요! |
||
|
||
} | ||
} | ||
|
||
|
||
fun main(){ | ||
val sol = 킹() | ||
sol.solution() | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.