ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/1966
// ํ์ ๊ฐ๋
์ด ์์ฉ๋ ๋ฌธ์
package main
import (
"bufio"
"fmt"
"os"
)
type printValues struct {
initIndex int
value int
}
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var t int
fmt.Fscanln(reader, &t)
for i := 0; i < t; i++ {
var n, m int
fmt.Fscanln(reader, &n, &m)
var queue = make([]printValues, n)
for j := 0; j < n; j++ {
fmt.Fscanf(reader, "%d ", &queue[j].value)
queue[j].initIndex = j
}
printCount := 0
for len(queue) > 0 {
printIndex := 0
for i := 1; i < len(queue); i++ {
if queue[0].value < queue[i].value {
printIndex = i
break
}
}
if printIndex > 0 {
queue = append(queue[1:], queue[0])
} else {
printCount++
if queue[0].initIndex == m {
fmt.Fprintln(writer, printCount)
}
queue = queue[1:]
}
}
}
}
๐จ Python3
# https://www.acmicpc.net/problem/1966
# ํ์ ๊ฐ๋
์ด ์์ฉ๋ ๋ฌธ์
import sys
if __name__ == "__main__":
t = int(sys.stdin.readline())
for i in range(t):
n, m = list(map(int, sys.stdin.readline().split()))
q = list(map(int, sys.stdin.readline().split()))
queue = []
for j, v in enumerate(q):
queue.append((j, v))
print_count = 0
while len(queue) > 0:
if queue[0][1] == max(q):
print_count += 1
if queue[0][0] == m:
print(print_count)
break
else:
q.pop(0)
queue.pop(0)
else:
q.append(q.pop(0))
queue.append(queue.pop(0))
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 1021๋ฒ / ํ์ ํ๋ ํ [Go][Python3] (0) | 2020.11.14 |
---|---|
BOJ / 10866๋ฒ / ๋ฑ [Go][Python3] (0) | 2020.11.13 |
BOJ / 11866๋ฒ / ์์ธํธ์ค ๋ฌธ์ 0 [Go][Python3] (0) | 2020.11.11 |
BOJ / 2164๋ฒ / ์นด๋2 [Go][Python3] (0) | 2020.11.10 |
BOJ / 18258๋ฒ / ํ 2 [Go][Python3] (0) | 2020.11.09 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- go
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ํ
- ์๋ฐ
- BFS
- ์ด๋ถํ์
- Algorithm
- java
- MongoDB
- ๋ชฝ๊ณ ๋๋น
- ์๊ฐ๊ต์ฒด
- AWS
- ํ๋ก์ด๋์์ฌ
- ๋งฅ๋ถํ๋ก
- ์คํ
- ํด์๋งต
- Macbook pro 2012 mid 13
- BOJ
- ๋ฐฑ์ค
- ballet
- Golang
- ์๊ณ ๋ฆฌ์ฆ
- dp
- python3
- ๋ธ๋ฃจํธํฌ์ค
- baekjoon
- ๋งฅ๋ถ
- dfs
- ๋ฐ๋
- ๋ถํ ์ ๋ณต
- Total
- Today
- Yesterday