문제풀이
BOJ 14891 : 톱니바퀴
pwerty
2025. 5. 12. 15:51
톱니바퀴 문제는 특정한 한 톱니바퀴 회전에 따라 다른 톱니바퀴의 회전 여부, 회전한다면 그 이후의 회전 영향도를 확인하되 중복으로 일어나지 않도록 신경쓰는 내용이 주가 되는 문제이다. 이정도 던져진 한 줄 요약 아이디어로 떠오르는게 있다면 당장 풀어본다면 좋을 것 같다.
https://www.acmicpc.net/problem/14891
나는 또 파일럿 코에게 마무리를 맡겨버렸다...................
굳이 따지면 BFS의 토대가 되는 느낌의 문제였다고 생각했다. 난 BFS를 정말 좋아하는데, 이건 생각외로 헷갈렸다. 근데 전체적인 구조는 좋았는데 인덱스에 대한 실수를 했던걸 보면 좀 빡빡하게 볼걸 생각이 든다.
근데 난 핀토스 하고 있고, 팀원들에게 민폐될라 더는 한 문제에 좋다고 몰입 할 수 없었다.
import sys
from collections import deque
input = sys.stdin.readline
totalCycle = []
for i in range(4):
totalCycle.append(list(map(int,input().strip())))
testCaseCnt = int(input())
testCase = deque()
for i in range(testCaseCnt):
testCase.append(list(map(int, input().split()))[:2])
while(testCase):
turnCase = deque()
turnCase.append(testCase.popleft())
isTurned = [False] * 4
isScanned = [False] * 4
while(turnCase):
whatCycle, turnPos = turnCase.popleft()
isTurned[whatCycle - 1] = True
# 회전 대상에 대한 회전 여지 확인
if whatCycle > 1: # 첫 번째 톱니바퀴가 아닐 때
if not (isTurned[whatCycle - 2] or isScanned[whatCycle - 2]):
if totalCycle[whatCycle - 1][6] != totalCycle[whatCycle - 2][2]:
turnCase.append([whatCycle - 1, turnPos * -1])
if whatCycle < 4: # 마지막 톱니바퀴가 아닐 때
if not (isTurned[whatCycle] or isScanned[whatCycle]):
if totalCycle[whatCycle - 1][2] != totalCycle[whatCycle][6]:
turnCase.append([whatCycle + 1, turnPos * -1])
# 실제 회전 시작
# 시계 방향 회전
if turnPos > 0:
temp = totalCycle[whatCycle - 1][7]
for i in range(7, 0, -1):
totalCycle[whatCycle - 1][i] = totalCycle[whatCycle - 1][i - 1]
totalCycle[whatCycle - 1][0] = temp
# 반시계 방향 회전
else:
temp = totalCycle[whatCycle - 1][0]
for i in range(7):
totalCycle[whatCycle - 1][i] = totalCycle[whatCycle - 1][i + 1]
totalCycle[whatCycle - 1][7] = temp
score = 0
if(totalCycle[0][0] == 1):
score += 1
if(totalCycle[1][0] == 1):
score += 2
if(totalCycle[2][0] == 1):
score += 4
if(totalCycle[3][0] == 1):
score += 8
print(score)
근데 내 VSC에 독 탄 느낌. 아무것도 안했는데 얘는 내가 뭘 풀려는지 알고있어서 기분나쁘다.
이래서 사람들이 산으로 자연인 하러 도망가는건가?