https://www.acmicpc.net/problem/2641
2641번: 다각형그리기
모눈종이에 다각형을 그리려고 한다. 그리는 방법은 모양수열로 표시된다. 모양수열은 1과 4사이의 숫자가 연속되어 나열된 것으로 1은 오른쪽으로, 2는 위쪽으로, 3은 왼쪽으로, 4는 아래쪽으로
www.acmicpc.net
Key Point
[Python] deque사용해서 리스트 회전하기
파이썬 알고리즘을 풀다보면 리스트를 회전하는 문제에 많이 직면하게 된다. 이는 python collection 모듈의 deque 자료형을 사용하면된다.리스트 자료형을 deque자료형으로 바꾼후 rotate()함수를 이용
velog.io
from collections import deque
convert = lambda x: (x + 2) % 4 if x != 2 else 4
n = int(input())
data = deque(map(int, input().split()))
rev_data = deque(map(convert, data))
rev_data.reverse()
count = 0
result = []
for _ in range(int(input())):
cur = deque(map(int, input().split()))
tmp = cur.copy()
for _ in range(n):
if data == tmp or rev_data == tmp:
count += 1
result.append(cur)
tmp.rotate(1)
print(count)
for result_list in result:
print(*result_list)
1. lambda + map 활용
2. deque.rotate() 활용
'백준 알고리즘 (Baekjoon Algorithm)' 카테고리의 다른 글
[파이썬] 백준 알고리즘 No.15815 천재 수학자 성필 (후위 연산자) (0) | 2024.01.19 |
---|---|
[파이썬] 백준 알고리즘 No.1024 수열의 합 (0) | 2024.01.16 |
[파이썬] 백준 알고리즘 No.1308 D-Day (0) | 2024.01.16 |
[파이썬] 백준 알고리즘 No.2477 참외밭 (2) | 2023.02.18 |
[파이썬] 백준 알고리즘 No.11478 서로 다른 부분 문자열의 개수 (0) | 2023.02.18 |