ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/11866
// ํ๋ฅผ ์ด์ฉํด ์ ๊ฑฐ ๊ณผ์ ์ ๊ตฌํํ๋ ๋ฌธ์
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n, k int
fmt.Fscanln(reader, &n, &k)
var queue, result []int
for i := 1; i <= n; i++ {
queue = append(queue, i)
}
var delIdx int
for len(queue) > 0 {
delIdx = (delIdx + k - 1) % len(queue)
result = append(result, queue[delIdx])
queue = append(queue[:delIdx], queue[delIdx+1:]...)
}
for i, v := range result {
if i == 0 {
fmt.Fprintf(writer, "<%d", v)
} else {
fmt.Fprintf(writer, ", %d", v)
}
}
fmt.Fprintln(writer, ">")
}
๐จ Python3
# https://www.acmicpc.net/problem/11866
# ํ๋ฅผ ์ด์ฉํด ์ ๊ฑฐ ๊ณผ์ ์ ๊ตฌํํ๋ ๋ฌธ์
import sys
from collections import deque
if __name__ == "__main__":
n, k = list(map(int, sys.stdin.readline().split()))
queue = deque(maxlen=n)
for i in range(1, n+1):
queue.append(i)
result = []
del_idx = 0
while len(queue) > 0:
del_idx = (del_idx+k-1)%len(queue)
result.append(queue[del_idx])
del queue[del_idx]
for i, v in enumerate(result):
if i == 0:
print("<{}".format(v), end='')
else:
print(", {}".format(v), end='')
print(">")
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 10866๋ฒ / ๋ฑ [Go][Python3] (0) | 2020.11.13 |
---|---|
BOJ / 1966๋ฒ / ํ๋ฆฐํฐ ํ [Go][Python3] (0) | 2020.11.12 |
BOJ / 2164๋ฒ / ์นด๋2 [Go][Python3] (0) | 2020.11.10 |
BOJ / 18258๋ฒ / ํ 2 [Go][Python3] (0) | 2020.11.09 |
BOJ / 1874๋ฒ / ์คํ ์์ด [Go][Python3] (0) | 2020.11.08 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ํ
- ๋งฅ๋ถํ๋ก
- go
- ํ๋ก์ด๋์์ฌ
- baekjoon
- BOJ
- dfs
- ๋งฅ๋ถ
- ๋ฐฑ์ค
- Macbook pro 2012 mid 13
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- Golang
- dp
- ์๊ฐ๊ต์ฒด
- ์๊ณ ๋ฆฌ์ฆ
- ์คํ
- ballet
- ์ด๋ถํ์
- ๋ธ๋ฃจํธํฌ์ค
- python3
- Algorithm
- java
- AWS
- BFS
- ํด์๋งต
- ๋ฐ๋
- ๋ถํ ์ ๋ณต
- ๋ชฝ๊ณ ๋๋น
- MongoDB
- ์๋ฐ
- Total
- Today
- Yesterday