Skip to content
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

11-wkdghdwns199 #47

Merged
merged 7 commits into from
Mar 6, 2024
Merged

11-wkdghdwns199 #47

merged 7 commits into from
Mar 6, 2024

Conversation

wkdghdwns199
Copy link
Collaborator

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

https://www.acmicpc.net/problem/11866

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

20๋ถ„ - ๊ฐœ๊ฐ• ์ „ ๋‚  ์‹ฌ์‹ ๋ฏธ์•ฝ์œผ๋กœ ๊ณ ๋ฅธ ๊ฐœ๋… ๋ฌธ์ œ

๋ฌธ์ œ
์š”์„ธํ‘ธ์Šค ๋ฌธ์ œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

1๋ฒˆ๋ถ€ํ„ฐ N๋ฒˆ๊นŒ์ง€ N๋ช…์˜ ์‚ฌ๋žŒ์ด ์›์„ ์ด๋ฃจ๋ฉด์„œ ์•‰์•„์žˆ๊ณ , ์–‘์˜ ์ •์ˆ˜ K(โ‰ค N)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด์ œ ์ˆœ์„œ๋Œ€๋กœ K๋ฒˆ์งธ ์‚ฌ๋žŒ์„ ์ œ๊ฑฐํ•œ๋‹ค. ํ•œ ์‚ฌ๋žŒ์ด ์ œ๊ฑฐ๋˜๋ฉด ๋‚จ์€ ์‚ฌ๋žŒ๋“ค๋กœ ์ด๋ฃจ์–ด์ง„ ์›์„ ๋”ฐ๋ผ ์ด ๊ณผ์ •์„ ๊ณ„์†ํ•ด ๋‚˜๊ฐ„๋‹ค. ์ด ๊ณผ์ •์€ N๋ช…์˜ ์‚ฌ๋žŒ์ด ๋ชจ๋‘ ์ œ๊ฑฐ๋  ๋•Œ๊นŒ์ง€ ๊ณ„์†๋œ๋‹ค. ์›์—์„œ ์‚ฌ๋žŒ๋“ค์ด ์ œ๊ฑฐ๋˜๋Š” ์ˆœ์„œ๋ฅผ (N, K)-์š”์„ธํ‘ธ์Šค ์ˆœ์—ด์ด๋ผ๊ณ  ํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด (7, 3)-์š”์„ธํ‘ธ์Šค ์ˆœ์—ด์€ <3, 6, 2, 7, 5, 1, 4>์ด๋‹ค.

N๊ณผ K๊ฐ€ ์ฃผ์–ด์ง€๋ฉด (N, K)-์š”์„ธํ‘ธ์Šค ์ˆœ์—ด์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์ž…๋ ฅ
์ฒซ์งธ ์ค„์— N๊ณผ K๊ฐ€ ๋นˆ ์นธ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. (1 โ‰ค K โ‰ค N โ‰ค 1,000)

์ถœ๋ ฅ
์˜ˆ์ œ์™€ ๊ฐ™์ด ์š”์„ธํ‘ธ์Šค ์ˆœ์—ด์„ ์ถœ๋ ฅํ•œ๋‹ค.

์˜ˆ์ œ ์ž…๋ ฅ 1
7 3

์˜ˆ์ œ ์ถœ๋ ฅ 1
<3, 6, 2, 7, 5, 1, 4>

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

์›์œผ๋กœ ๋‘˜๋Ÿฌ์‹ธ์—ฌ ์žˆ๋‹ค๋Š” ๊ฐœ๋… ๋•Œ๋ฌธ์— ์ข€ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์•ž์— ์žˆ๋Š” ๊ฐ’๋“ค์„ ๋’ค๋กœ ๋ฌผ๋ ค์ฃผ๋ฉด ๋œ๋‹ค๋Š” ์ƒ๊ฐ์„ ํ•˜๋ฉด ์‰ฝ์Šต๋‹ˆ๋‹ค.

์˜ˆ์ œ ์ž…๋ ฅ์œผ๋กœ ์˜ˆ๋ฅผ ๋“ค์–ด๋ณด๋ฉด

1. 7 3 ๋ฅผ ์ž…๋ ฅํ•œ๋‹ค.

2. [1,2,3,4,5,6,7] ์—์„œ 3๋ฒˆ ์‚ฌ๋žŒ์„ ์ œ๊ฑฐํ•ด์•ผ ํ•œ๋‹ค.

3. [3,4,5,6,7,1,2] ์ด๋Ÿฐ ์‹์œผ๋กœ 3๋ฒˆ์„ ๋งจ ์•ž์œผ๋กœ ๊ฐ€์ ธ์˜ค๊ณ  1,2 ๋ฅผ ๋’ค๋กœ ๋ณด๋‚ธ๋‹ค . (rotate() ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•œ๋‹ค)

4. ๋งจ ์•ž์˜ ์ˆซ์ž 3 ์„ popํ•˜๊ณ , ์ด๋ฅผ ๊ณ„์† ๋ฐ˜๋ณตํ•˜๋ฉด ์ œ๊ฑฐํ•ด์•ผ ํ•˜๋Š” ์ˆœ์„œ๋Œ€๋กœ ์ˆซ์ž๊ฐ€ ๋‚˜์˜จ๋‹ค.
import sys
from collections import deque
input = sys.stdin.readline

N, K= map(int, input().split())
circle_list = deque([number for number in range(1,N+1)])
print('<', end='')
while circle_list :
    circle_list.rotate(-(K-1))
    print(circle_list.popleft(), end='')
    if len(circle_list) != 0 : print(', ', end='')
print('>')

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

@alstjr7437
Copy link
Member

์ €๋Š” ์˜ˆ์ „์— ํ‘ผ ํ’€์ด๊ฐ€ ์žˆ๋Š”๋ฐ ๋”ฐ๋กœ ํ๋ฅผ ์•ˆ์“ฐ๊ณ  ์Šคํƒ๋งŒ ์จ์„œ ํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค!!
๊ทธ๋ฆฌ๊ณ  ํ’€์ด๋ฅผ ์กฐ๊ธˆ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค!

n, k = map(int, input().split())
yosaepoos = []
result = []
a = 0
for i in range(1, n+1):
    yosaepoos.append(i)

while yosaepoos :
    # ์ฒ˜์Œ์„ ์˜ˆ๋กœ ์žก์œผ๋ฉด 0 + 3 - 1 = 2 ์ด๋ฏ€๋กœ else๊ฐ€ ๋Œ์•„๊ฐ
    # ๊ทธ ๋‹ค์Œ 2+2๋กœ 4๊ฐ€ ๋“ค์–ด๊ฐ€์„œ 6์ด(2๊ฐ€ ๋‚˜๊ฐ”์œผ๋ฏ€๋กœ 4๋Š” 6์ด๋‚˜์˜ด) ๋‚˜์˜ด 
    # ๊ณ„์†ํ•ด์„œ ๋‹ค์Œ ๋ฐฐ์—ด๋ณด๋‹ค ์ž‘์ง€ ์•Š์œผ๋ฉด else๋กœ ๋Œ์•„๊ฐ€๋ฉด์„œ a์—๋‹ค๊ฐ€ k-1(2)๋งŒํผ ๋”ํ•จ
    # ์Šคํƒ๋ณด๋‹ค ์ž‘์•„์ง€๋ฉด a๋ฅผ ์Šคํƒ๊ธธ์ด๋งŒํผ ๋นผ์„œ ๊ฐฑ์‹ ํ•จ
    if  a + k - 1 >= len(yosaepoos):
        a = a - len(yosaepoos)
    else : 
        result.append(yosaepoos.pop(a + k - 1))
        a = a + k - 1

# ๊ฒฐ๊ณผ ์ถœ๋ ฅ ๋ถ€๋ถ„
print("<", end = "")
for i in result:
    if i == result[-1]:
        print(i, end="")
    else :
        print(i, end=", ")

print(">")

@alstjr7437 alstjr7437 removed the request for review from fnzksxl March 3, 2024 12:11
@alstjr7437
Copy link
Member

์ž ๊ทธ๋ฆฌ๊ณ  ์ด์ œ ๋‹ค์Œ ๋‹จ๊ณ„๋กœ ์ง„ํ™”ํ•ด์•ผ๊ฒ ์ฃ ??

image

@wkdghdwns199
Copy link
Collaborator Author

@alstjr7437 ์•„์ž‡ ๋นจ๋ฆฌ ํ• ๊ฒŒ์š” ใ…œใ… 

Copy link
Collaborator

@SeongHoonC SeongHoonC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋”ฑํžˆ ๋ฆฌ๋ทฐํ• ๊ฒŒ ์—†๊ตฐ์š” ์ €๋Š” ๋ฆฌ์ŠคํŠธ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹น

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val (n, k) = br.readLine().split(" ").map { it.toInt() }

    val list = List(n) { it + 1 }.toMutableList()
    val answer = mutableListOf<Int>()
    var index = 0

    while (list.isNotEmpty()) {
        index = (index + (k - 1)) % list.size
        answer.add(list.removeAt(index))
    }
    println("<${answer.joinToString(", ")}>")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants