-
[백준] 3048번 개미(python)Python/BAEKJOON 2022. 1. 19. 15:14728x90
문제)
알고리즘)
- g1과 g2 2개의 그룹으로 나누고 기준이 될 g1은 reverse 상태로 변환 후 result에 g1+g2로 저장
- 해당 초에 result 리스트 값을 반복해서 조건에 맞는 값을 자리 바꿈
- 진행 시간(num)과 입력 시간(time)이 같다면 종료 후 최종 출력
코드)
import sys input = sys.stdin.readline g1_cnt, g2_cnt = map(int, input().split()) g1 = list(reversed(input().rstrip())) #진행방향에 맞게 reverse g2 = list(input().rstrip()) time = int(input()) result = g1 + g2 num = 0 #시간 기준 while num < time: #해당 시간초에 개미들의 변화 for i in result[:-1]: # 마지막 값은 result[-2]값 순서에서 처리함 x = result.index(i) if i in g1: #순서를 뒤집는데 기준이 되는 g1 if result[x+1] in g2: result[x], result[x+1] = result[x+1], result[x] else: continue else: continue num += 1 #다음 시간 for p in result: #출력 print(p, end='')
728x90'Python > BAEKJOON' 카테고리의 다른 글
[백준] 1260번 DFS와 BFS(python) (0) 2022.01.29 [백준] 2606번 바이러스(python) (0) 2022.01.23 [백준] 8911번 거북이(python) (0) 2022.01.21 [백준] 2841번 외계인의 기타연주(python) (0) 2022.01.08 [백준] 16918번 봄버맨(python) (0) 2022.01.04