[BOJ]コンベアのロボット-20055
📃 質問する
[BOJ]コンベア上のロボット🔗リンク
アクセス題は4つの動作に分かれています.
①ベルト、ロボットが1コマ回転します.
②最初にベルトをつけたロボットから、前に一コマ移動できるようにしましょう.
(ロボットがあるか、耐久性があるかをチェック)
③上の位置に格子の耐久性がある場合は、ロボットを上に置きます.
④耐久度が0のマス数がK個を超えると終了する. 🧠 に答える
[BOJ]コンベア上のロボット🔗リンク
アクセス
①ベルト、ロボットが1コマ回転します.
②最初にベルトをつけたロボットから、前に一コマ移動できるようにしましょう.
(ロボットがあるか、耐久性があるかをチェック)
③上の位置に格子の耐久性がある場合は、ロボットを上に置きます.
④耐久度が0のマス数がK個を超えると終了する.
import sys
from collections import deque
input = sys.stdin.readline
N, K = map(int, input().split())
conveyor = deque(list(map(int, input().split())))
boxRobot = deque([0]*N)
count = 0
while(True):
count += 1
## Step 1 : Move Conveyor
conveyor.rotate(1)
boxRobot.rotate(1)
boxRobot[-1] = 0
## Step 2 : Move Robots
if sum(boxRobot):
for idx in range(N-2, -1, -1):
if(boxRobot[idx] and boxRobot[idx+1] == 0 and conveyor[idx+1]):
boxRobot[idx] = 0
boxRobot[idx+1] = 1
conveyor[idx+1] -= 1
boxRobot[-1] = 0
## Step 3 : Put Robot on the first
if(conveyor[0]):
boxRobot[0] = 1
conveyor[0] -= 1
## Step 4 : Counting Durability
if(conveyor.count(0) >= K):
break
print(count)
Reference
この問題について([BOJ]コンベアのロボット-20055), 我々は、より多くの情報をここで見つけました https://velog.io/@xcv3549/BOJ-컨베이어-벨트-위의-로봇-20055テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol