https://www.acmicpc.net/problem/1966
1966๋ฒ: ํ๋ฆฐํฐ ํ
์ฌ๋ฌ๋ถ๋ ์๋ค์ํผ ์ฌ๋ฌ๋ถ์ ํ๋ฆฐํฐ ๊ธฐ๊ธฐ๋ ์ฌ๋ฌ๋ถ์ด ์ธ์ํ๊ณ ์ ํ๋ ๋ฌธ์๋ฅผ ์ธ์ ๋ช ๋ น์ ๋ฐ์ ‘์์๋๋ก’, ์ฆ ๋จผ์ ์์ฒญ๋ ๊ฒ์ ๋จผ์ ์ธ์ํ๋ค. ์ฌ๋ฌ ๊ฐ์ ๋ฌธ์๊ฐ ์์ธ๋ค๋ฉด Queue ์๋ฃ๊ตฌ์กฐ์
www.acmicpc.net
times = int(input())
result = []
for _ in range(times):
size,point = map(int,input().split())
pri = list(map(int,input().split()))
count = 0
while(True):
maxindex = pri.index(max(pri))
if(maxindex == point):
result.append(count+1)
break
elif(point < maxindex):
point = size-(maxindex+1)+point
else:
point = point - (maxindex+1)
temp = pri[0:maxindex]
pri = pri[maxindex+1:]
pri.extend(temp)
size-=1
count += 1
for i in result:
print(i)
'๐ฅ๏ธSW Engineer > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค]2775-๋ถ๋ ํ์ฅ์ด ๋ ํ ์ผ (0) | 2023.01.18 |
---|---|
[๋ฐฑ์ค]11866-์์ธํธ์ค ๋ฌธ์ (0) | 2023.01.18 |
[๋ฐฑ์ค]2609-์ต๋๊ณต์ฝ์์ ์ต์๊ณต๋ฐฐ์ ๊ตฌํ๊ธฐ (0) | 2023.01.09 |
[๋ฐฑ์ค]11651-์ขํ ์ ๋ ฌํ๊ธฐ2 (0) | 2023.01.07 |
[๋ฐฑ์ค]10773-์ ๋ก (0) | 2023.01.05 |