-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Week1] 박서윤: 차이를 최대로, 부분수열의 합, 마인크래프트, 퇴사, 소수찾기 #5
Merged
Merged
Changes from all commits
Commits
Show all changes
5 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 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,45 @@ | ||
import kotlin.math.sqrt | ||
|
||
class Solution { | ||
var visited = BooleanArray(7, {false}) | ||
val set: MutableSet<Int> = mutableSetOf() | ||
var depth: Int = 0 | ||
|
||
fun solution(numbers: String): Int { | ||
var answer = 0 | ||
findPrimes(numbers,0, "") | ||
answer = set.size | ||
|
||
return answer | ||
} | ||
|
||
fun findPrimes(numbers: String, depth: Int, cur: String) { | ||
if (depth == numbers.length) return | ||
|
||
for (i in 0 until numbers.length) { | ||
if (visited[i] == true) { | ||
continue | ||
} | ||
else { | ||
var number = cur + numbers[i] | ||
|
||
if (isPrime(number.toInt())) { | ||
set.add(number.toInt()) | ||
} | ||
visited[i] = true | ||
findPrimes(numbers, depth + 1, number) | ||
visited[i] = false | ||
} | ||
} | ||
} | ||
|
||
fun isPrime(num: Int): Boolean { | ||
if (num <= 1) return false | ||
if (num > 1) { | ||
for (i in 2 .. sqrt(num.toDouble()).toInt()) { | ||
if (num % i == 0) return false | ||
} | ||
} | ||
return true | ||
} | ||
} |
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,32 @@ | ||
val n = readln().toInt() | ||
val arr = readln().split(" ").map{it.toInt()}.toIntArray() | ||
var newArr = IntArray(n) | ||
var visited = BooleanArray(n, {false}) | ||
var max: Int = Int.MIN_VALUE | ||
|
||
fun main() { | ||
permutation(0) | ||
println(max) | ||
} | ||
|
||
fun permutation(depth: Int) { | ||
if (depth == n) { | ||
var sum = 0; | ||
for (i in 0 until n-1) { | ||
sum += Math.abs(newArr[i] - newArr[i+1]) | ||
} | ||
max = Math.max(max, sum) | ||
} | ||
|
||
for (i in 0 until n) { | ||
if (visited[i] == true) { | ||
continue | ||
} | ||
else { | ||
newArr[depth] = arr[i] | ||
visited[i] = true | ||
permutation(depth + 1) | ||
visited[i] = false | ||
} | ||
} | ||
} |
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,49 @@ | ||
import java.util.StringTokenizer | ||
|
||
fun main() { | ||
val (n, m ,b) = readln().split(" ").map{it.toInt()} | ||
val ground = Array(n, {IntArray(m, {0})}) | ||
|
||
var high = Int.MIN_VALUE | ||
var low = Int.MAX_VALUE | ||
|
||
for (i in 0 until n) { | ||
val st = StringTokenizer(readln(), " ") | ||
for (j in 0 until m) { | ||
ground[i][j] = Integer.parseInt(st.nextToken()) | ||
high = Math.max(high, ground[i][j]) | ||
low = Math.min(low, ground[i][j]) | ||
} | ||
} | ||
|
||
solution(n, m, b, ground, high, low) | ||
} | ||
|
||
fun solution(n: Int, m: Int, b: Int, ground: Array<IntArray>, high: Int, low: Int) { | ||
var ansSec = Int.MAX_VALUE | ||
var ansHigh = 0 | ||
|
||
for (x in low .. high) { | ||
var sec = 0 | ||
var tmpB = b | ||
|
||
for (i in 0 until n) { | ||
for (j in 0 until m) { | ||
if (ground[i][j] > x) { | ||
sec += (ground[i][j] - x) * 2 | ||
tmpB += (ground[i][j] - x) | ||
} | ||
else if (ground[i][j] < x) { | ||
sec += (x - ground[i][j]); | ||
tmpB -= (x - ground[i][j]); | ||
} | ||
} | ||
} | ||
|
||
if (tmpB >= 0 && sec <= ansSec) { | ||
ansSec = sec | ||
ansHigh = x | ||
} | ||
} | ||
print("$ansSec $ansHigh") | ||
} |
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,22 @@ | ||
import java.lang.Math.max | ||
|
||
fun main() { | ||
val n = readln().toInt() | ||
val T = IntArray(n + 1) | ||
val P = IntArray(n + 1) | ||
val arr = IntArray(n + 2) | ||
|
||
for (i in 1 .. n) { | ||
val input = readln().split(" ").map{it.toInt()} | ||
T[i] = input[0] | ||
P[i] = input[1] | ||
} | ||
|
||
for (i in 1 .. n) { | ||
if (i + T[i] <= n + 1) { | ||
arr[i + T[i]] = max(arr[i + T[i]], arr[i] + P[i]) | ||
} | ||
arr[i + 1] = max(arr[i + 1], arr[i]) | ||
} | ||
println(arr[n + 1]) | ||
} |
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,25 @@ | ||
var ans:Int = 0 | ||
|
||
fun main() { | ||
val (n, s) = readln().split(" ").map{it.toInt()} | ||
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. .split(" ").map{it.toInt()} |
||
val arr = readln().split(" ").map{it.toInt()}.toIntArray() | ||
|
||
subSum(n, s, arr,0, 0, 0) | ||
|
||
if (s == 0) { | ||
ans-- | ||
} | ||
println(ans) | ||
} | ||
|
||
fun subSum(n: Int, s: Int, arr: IntArray, depth: Int, idx: Int, sum: Int) { | ||
if (depth == n) { | ||
if (sum == s) { | ||
ans++ | ||
} | ||
return | ||
} | ||
|
||
subSum(n, s, arr, depth + 1, idx + 1, sum + arr[idx]); | ||
subSum(n, s, arr, depth + 1, idx + 1, sum); | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BooleanArray 기본값이 false라 초기값 안써도 될거에요