250x250
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
- 스토어드 프로시저
- 다대일
- SQL프로그래밍
- 연관관계
- 스프링 폼
- 힙
- exclusive lock
- 연결리스트
- BOJ
- FetchType
- 유니크제약조건
- eager
- shared lock
- JPQL
- 이진탐색
- dfs
- 지연로딩
- querydsl
- execute
- 즉시로딩
- 다대다
- 데코레이터
- 낙관적락
- 백트래킹
- 비관적락
- CHECK OPTION
- 일대다
- PS
- 동적sql
- fetch
Archives
- Today
- Total
흰 스타렉스에서 내가 내리지
[BOJ] (구현) 20327번 배열돌리기 6 본문
728x90
별다른 스킬이 필요한 문제는 아니었지만, 배열을 돌리는 다양한 상황을 연습할 수 있었다.
나중에 참고할 때가 있을 것 같아 코드를 업로드 해본다.
def oper1(arr, l):
n = len(arr)
s = 2**l
for x in range(0, n, s):
for y in range(0, n, s):
tmp = []
for i in range(s):
row = []
for j in range(s):
row.append(arr[x+i][y+j])
tmp.append(row)
tmp = reverseTopDown(tmp)
for i in range(s):
for j in range(s):
arr[x+i][y+j] = tmp[i][j]
return arr
def oper2(arr, l):
n = len(arr)
s = 2**l
for x in range(0, n, s):
for y in range(0, n, s):
tmp = []
for i in range(s):
row = []
for j in range(s):
row.append(arr[x+i][y+j])
tmp.append(row)
tmp = reverseLeftRight(tmp)
for i in range(s):
for j in range(s):
arr[x+i][y+j] = tmp[i][j]
return arr
def oper3(arr, l):
n = len(arr)
s = 2**l
for x in range(0, n, s):
for y in range(0, n, s):
tmp = []
for i in range(s):
row = []
for j in range(s):
row.append(arr[x+i][y+j])
tmp.append(row)
tmp = rotateRight(tmp)
for i in range(s):
for j in range(s):
arr[x+i][y+j] = tmp[i][j]
return arr
def oper4(arr, l):
n = len(arr)
s = 2**l
for x in range(0, n, s):
for y in range(0, n, s):
tmp = []
for i in range(s):
row = []
for j in range(s):
row.append(arr[x+i][y+j])
tmp.append(row)
tmp = rotateLeft(tmp)
for i in range(s):
for j in range(s):
arr[x+i][y+j] = tmp[i][j]
return arr
def oper5(arr, l):
n = len(arr)
new_arr = [[0]*n for _ in range(n)]
s = 2**l
for x in range(0, n, s):
for y in range(0, n, s):
tmp = []
for i in range(s):
row = []
for j in range(s):
row.append(arr[x+i][y+j])
tmp.append(row)
for i in range(s):
for j in range(s):
new_arr[n-s-x+i][y+j] = tmp[i][j]
return new_arr
def oper6(arr, l):
n = len(arr)
new_arr = [[0]*n for _ in range(n)]
s = 2**l
for x in range(0, n, s):
for y in range(0, n, s):
tmp = []
for i in range(s):
row = []
for j in range(s):
row.append(arr[x+i][y+j])
tmp.append(row)
for i in range(s):
for j in range(s):
new_arr[x+i][n-s-y+j] = tmp[i][j]
return new_arr
def oper7(arr, l):
n = len(arr)
new_arr = [[0]*n for _ in range(n)]
s = 2**l
for x in range(0, n, s):
for y in range(0, n, s):
tmp = []
for i in range(s):
row = []
for j in range(s):
row.append(arr[x+i][y+j])
tmp.append(row)
for i in range(s):
for j in range(s):
new_arr[i+y][n-s-x+j] = tmp[i][j]
return new_arr
def oper8(arr, l):
n = len(arr)
new_arr = [[0]*n for _ in range(n)]
s = 2**l
for x in range(0, n, s):
for y in range(0, n, s):
tmp = []
for i in range(s):
row = []
for j in range(s):
row.append(arr[x+i][y+j])
tmp.append(row)
for i in range(s):
for j in range(s):
new_arr[i+n-s-y][j+x] = tmp[i][j]
return new_arr
def reverseTopDown(arr):
n = len(arr)
m = len(arr[0])
tmp = [[0]*m for _ in range(n)]
for i in range(n):
for j in range(m):
tmp[i][j] = arr[n-i-1][j]
return tmp
def reverseLeftRight(arr):
n = len(arr)
m = len(arr[0])
tmp = [[0]*m for _ in range(n)]
for i in range(n):
for j in range(m):
tmp[i][j] = arr[i][m-1-j]
return tmp
def rotateRight(arr):
n, m = len(arr), len(arr[0]) # 행, 열
result = [[0] * n for _ in range(m)]
for i in range(n):
for j in range(m):
result[j][n-1-i] = arr[i][j]
return result
def rotateLeft(arr):
n, m = len(arr), len(arr[0]) # 행, 열
result = [[0] * n for _ in range(m)]
for i in range(n):
for j in range(m):
result[m-1-j][i] = arr[i][j]
return result
def main():
N, R = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(2**N)]
for _ in range(R):
k, l = map(int, input().split())
if k==1:
arr = oper1(arr, l)
elif k==2:
arr = oper2(arr, l)
elif k==3:
arr = oper3(arr, l)
elif k==4:
arr = oper4(arr, l)
elif k==5:
arr = oper5(arr, l)
elif k==6:
arr = oper6(arr, l)
elif k==7:
arr = oper7(arr, l)
elif k==8:
arr = oper8(arr, l)
for a in arr:
print(*a)
main()
https://www.acmicpc.net/problem/20327
'Problem Solving' 카테고리의 다른 글
[BOJ] (BFS) 16928번 뱀과 사다리게임 (0) | 2022.05.10 |
---|---|
[BOJ] (구현) 1339번 단어수학 (0) | 2022.04.08 |
[BOJ](BF,구현) 1917번 정육면체 전개도 (0) | 2022.03.18 |
[BOJ] [구현]16931번 겉넓이 구하기 (0) | 2022.03.16 |
[BOJ] (DF) 13398번 연속합2 (0) | 2022.03.08 |