Notice
Recent Posts
Recent Comments
Link
반응형
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 강화학습
- 비지도학습
- 백준
- 파이썬 알고리즘
- 머신러닝
- 파이썬
- bineary search
- HTTP
- 이진탐색
- BOJ
- 코딩테스트
- 자바
- Merge sort
- 해시
- 파이썬 오류
- 코딩
- 프로그래머스
- 딥러닝
- 깊이우선탐색
- 멱등
- 알고리즘
- 캐싱
- 딕셔너리
- rest api
- 스택과 힙
- 코테
- 지도학습
- 너비우선탐색
- 오버라이딩
- post
Archives
- Today
- Total
chae._.chae
# 3048 - 개미 본문
728x90
반응형

n1, n2 = map(int, input().split())
ant1 = list(str(input())) # 개미순서 문자열로 입력
ant2 = list(str(input()))
time = int(input())
ant1.reverse() # 더하는 방향을 맞춰준다
ant_sum = ant1 + ant2 # 개미 순서 합치기
for i in range(time):
temp = []
for j in range(1, len(ant_sum)):
if ant_sum[j] in ant2:
if ant_sum[j-1] in ant1: # 그룹1에 있는 개미이면 점프해 위치가 바뀌어야 하므로, temp배열에 인덱스값 저장
temp.append(j)
for q in temp: # 방향이 다른 두 개미 위치 바꿔주기
ant_sum[q] , ant_sum[q-1] = ant_sum[q-1], ant_sum[q]
print(ant_sum)
result='' # 리스트인 결과를 문자열로 출력하기 위한 과정
for i in ant_sum:
result += i
print(result)
https://www.acmicpc.net/problem/3048
3048번: 개미
T초가 지난 후에 개미의 순서를 출력한다. 첫 번째 개미 그룹은 왼쪽에서 오른쪽으로 움직이고, 두 번째 그룹은 반대 방향으로 움직인다.
www.acmicpc.net
728x90
'파이썬 알고리즘 > BOJ' 카테고리의 다른 글
| [Algorithm] 백준 #1946 - 신입사원 (0) | 2022.03.29 |
|---|---|
| [Algorithm] 백준 #2108 - 통계학 (0) | 2022.03.29 |
| #18238 - ZOAC 2 (0) | 2022.01.09 |
| #10773 - 제로 (0) | 2021.12.30 |
| #2839 - 설탕배달 (0) | 2021.12.17 |