Git Product home page Git Product logo

algo-study's Introduction

Algo-Study

๐Ÿ‘‘ย Rule

  • ๋งค์ฃผ ์›”, ์ˆ˜, ๊ธˆ ์˜คํ›„ 6 ์‹œ์— ๋ชจ์—ฌ์„œ ์ฝ”๋“œ ๋ฆฌ๋ทฐ
  • ๋ฌธ์ œ ํด๋”์— ๊ฐ์ž ํ‘ผ ๋ฌธ์ œ ์—…๋กœ๋“œ
  • ํ’€์ง€ ๋ชปํ•  ๊ฒฝ์šฐ ํด๋”์— ์—…๋กœ๋“œ ํ›„ ํ”ผ๋“œ๋ฐฑ

๐ŸŒŸย Commit Message

BaekJoon : BOJ
Programmers : PRO
SW Expert Academy : SWEA
๋‹ค๋ฅธ ๋ฌธ์ œ ์‚ฌ์ดํŠธ๋Š” ETC๋กœ ํ‘œ๊ธฐ


  • GitHub commit ์–‘์‹ : [Platform | Language] ๋ฌธ์ œ ๋ฒˆํ˜ธ


๐Ÿงธย Member

Name GitHub
๊น€์ค€์„œ @adoo24
๋ฐ•์ƒํฌ @C0012S
๋ฐ•์ฐฝํ˜„ @gyeoul
์ด์ง€์€ @Jieun714
์ „์ƒํฌ @ybwi0912

algo-study's People

Contributors

gyeoul avatar c0012s avatar jieun714 avatar ybwi0912 avatar adoo24 avatar

algo-study's Issues

intํ˜• ๋ฐฐ์—ด์„ Arrays.asList() ๋ณ€ํ™˜์‹œ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ

14889๋ฒˆ์„ ํ’€์ดํ•  ๋•Œ
Arrays.asList(int[]).contains(a) ํ˜•ํƒœ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค ํ–ˆ๋Š”๋ฐ, ์ œ๋Œ€๋กœ๋œ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š์•„ ํ™•์ธํ•ด ๋ณธ ์ด์Šˆ.

Arrays.asList(intํ˜• ๋ฐฐ์—ด)๋Š” List<int []> ํ˜•ํƒœ๋กœ ๋ฐ˜ํ™˜ํ•˜๊ธฐ ๋•Œ๋ฌธ์— Object ํƒ€์ž…์ธ Integer ๋ฐฐ์—ด๋กœ ์„ ์–ธํ•ด์คŒ์œผ๋กœ์จ ํ•ด๊ฒฐ.

Autoboxing์€ ๋‹จ์ผ ์š”์†Œ์—์„œ๋งŒ ๋ฐœ์ƒํ•˜๋ฉฐ, primitives ๋ฐฐ์—ด์—์„œ๋Š” ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค.

์ฐธ๊ณ  ๊ธ€
https://stackoverflow.com/questions/1467913/arrays-aslist-not-working-as-it-should

[Python] set์ž๋ฃŒํ˜• ์•ˆ์— tuple์„ ๋„ฃ๋Š” ๋ฐฉ๋ฒ•

set ์•ˆ์— (x,y) ๊ฐ™์€ tuple์„ ๋„ฃ๊ณ  ์ดˆ๊ธฐํ™”ํ•  ๋•Œ
my_set = set((x,y)) ์™€ ๊ฐ™์ด ์ดˆ๊ธฐํ™” ํ•˜๋ฉด {x, y} ์ฒ˜๋Ÿผ ๊ฐ’ ๋‘๊ฐœ๊ฐ€ ์ถ”๊ฐ€๋ฉ๋‹ˆ๋‹ค.

my_set = {(x,y)} ์™€ ๊ฐ™์ด ์ดˆ๊ธฐํ™”ํ•˜๋ฉด ํ•˜๋‚˜์˜ ํŠœํ”Œ๋กœ element๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

BOJ 14500 dfs๋กœ ๋ณ€ํ™˜ ํ›„ ํ‹€๋ฆผ

์ฝ”๋“œ ๋„ˆ๋ฌด ๋”๋Ÿฌ์›Œ์„œ dfs ์‚ฌ์šฉํ•ด์„œ ํ’€์–ด๋ดค๋Š”๋ฐ ํ‹€๋ฆฌ๊ณ  ๋‚˜์„œ ๊ถ๊ธˆ์ 

package baekjoon.bruteforce._14500

import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.util.*


lateinit var numbers: Array<IntArray>
lateinit var isVisited: Array<BooleanArray>
val ans = TreeSet<Int>()
val delta = ArrayList<ArrayList<Pair<Int, Int>>>()
fun main() {
    val bf = BufferedReader(InputStreamReader(System.`in`))
    val bw = BufferedWriter(OutputStreamWriter(System.out))
    var st = StringTokenizer(bf.readLine()) // ์ž…๋ ฅ๋ฐ›๊ธฐ

    val rawi = st.nextToken().toInt() // i
    val rawj = st.nextToken().toInt() // j

    numbers = Array(rawi) { IntArray(rawj) } // ์ˆซ์ž ์ €์žฅํ•  ๋ฐฐ์—ด
    isVisited = Array(rawi) { BooleanArray(rawj) } // ๋ฐฉ๋ฌธํ–ˆ๋Š”์ง€ ์ €์žฅํ•  ๋ฐฐ์—ด(์ž๊ธฐ ์ž์‹  ๋‘๋ฒˆ ์ฐธ์กฐํ•˜๋ฉด ๊ฐ’ ๋ปฅํŠ€๊ธฐ๋จ)

    for (i in 0 until rawi) {
        st = StringTokenizer(bf.readLine())
        for (j in 0 until rawj) {
            numbers[i][j] = st.nextToken().toInt() // ๋ฐฐ์—ด์— ๊ฐ’ ์ €์žฅ
        }
    }

    tmino() // t๋ฏธ๋…ธ ๋ชจ์–‘ ์„ธํŒ…
    for (i in 0 until rawi) {
        for (j in 0 until rawj) {
            calculate(i, j) // t๋ฏธ๋…ธ ๊ณ„์‚ฐ
            for (k in isVisited){
                k.fill(false) // ๋ฐฉ๋ฌธ๋ฐฐ์—ด ์ดˆ๊ธฐํ™”
            }
            isVisited[i][j] = true // ์ฒซ๋…ธ๋“œ ๋ฐฉ๋ฌธ ์ฒดํฌ
            dfs(i, j, 1, numbers[i][j]) // dfs ์‹คํ–‰
        }
    }

    bw.write("${ans.last()}\n") // ๊ฐ’ ํ‘œ์‹œ(treeset ๊ฐ€์žฅ ํฐ๊ฐ’)
    bw.flush()
}

fun dfs(i: Int, j: Int, count: Int, sum: Int) {
    if (count == 4) { // 4๊ฐœ์ผ๋•Œ
        ans.add(sum) // ํ•ฉ ํŠธ๋ฆฌ์…‹์— ์ถ”๊ฐ€
        return // dfs ๋ ๋„๋‹ฌ ์ข…๋ฃŒ
    }

    val dx = arrayOf(0, 0, 1, -1) // ๋ธํƒ€๊ฐ’ ๊ฐ€๋กœ
    val dy = arrayOf(1, -1, 0, 0) // ๋ธํƒ€๊ฐ’ ์„ธ๋กœ

    for (n in 0..3) {
        val newi = dy[n] + i
        val newj = dx[n] + j
        if (newi < 0 || newi >= numbers.size) continue // ์„ธ๋กœ ๊ฐ’ ์œ ํšจ์ฒดํฌ
        if (newj < 0 || newj >= numbers[newi].size) continue // ๊ฐ€๋กœ ๊ฐ’ ์œ ํšจ์ฒดํฌ
        if (isVisited[newi][newj]) continue // ๋ฐฉ๋ฌธํ–ˆ์—ˆ๋Š”์ง€ ์ฒดํฌ
        isVisited[newi][newj] = true
        dfs(newi, newj, count + 1, sum + numbers[newi][newj])
    }
}

fun tmino() {
    delta.add(ArrayList())
    delta.last().add(Pair(0, 0))
    delta.last().add(Pair(0, 1))
    delta.last().add(Pair(-1, 0))
    delta.last().add(Pair(1, 0))
    delta.add(ArrayList())
    delta.last().add(Pair(0, 0))
    delta.last().add(Pair(0, -1))
    delta.last().add(Pair(-1, 0))
    delta.last().add(Pair(1, 0))
    delta.add(ArrayList())
    delta.last().add(Pair(0, 0))
    delta.last().add(Pair(0, -1))
    delta.last().add(Pair(-1, 0))
    delta.last().add(Pair(0, 1))
    delta.add(ArrayList())
    delta.last().add(Pair(0, 0))
    delta.last().add(Pair(0, -1))
    delta.last().add(Pair(1, 0))
    delta.last().add(Pair(0, 1))
}

fun calculate(i: Int, j: Int) {
    for (arrs in delta) {
        var sum = 0
        for (d in arrs) {
            val newi = d.first + i
            val newj = d.second + j
            if (newi < 0 || newi >= numbers.size) break
            if (newj < 0 || newj >= numbers[newi].size) break
            sum += numbers[newi][newj]
        }
        ans.add(sum)
    }
}

t๋ฏธ๋…ธ ์ œ์™ธํ•˜๊ณ  ๋‚˜๋จธ์ง€๋ฅผ dfs๋กœ ๋ฐ”๊ฟ”๋ดค๋Š”๋ฐ...

4 4
5 1 1 5
2 1 1 2
2 1 1 2
1 1 1 1

๋‹ต: 12 / ์ถœ๋ ฅ: 10
์œผ๋กœ ํ‹€๋ ค์„œ ์ƒ๊ฐ์ข€ ํ•ด๋ด์•ผ๋ ๋“ฏ..
dfs ๊ฐ’์„ 5๊ฐœ ๋ฐ›์œผ๋ฉด 14๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋‚˜์˜ค๋Š”๋ฐ 4๋Š” ์™œ 12๊ฐ€ ์•ˆ๋‚˜์˜ค๊ณ  10๋งŒ ๋‚˜์˜ฌ๊นŒ...

๋ชจ์–‘ ๋ชจ๋‘ ๋งŒ๋“ค์–ด์„œ ํ•ด๊ฒฐํ•˜๊ธด ํ–ˆ๋Š”๋ฐ..
https://github.com/Dream-Waves/Algo-Study/blob/495dda10521d3c7f9cd53dc684c0dfd4d2f9536a/baekjoon/bruteforce/_14500/gyeoul_14500.kt

Originally posted by @gyeoul in #24 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.