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