BAEKJOON : 14500, 1748, 15649
No. 17299
1. Problem
2. Others' Solutions
import sys
import math
tetrominos = [
[(0,0),(0,1),(0,2),(0,3)], # ㅡ
[(0,0),(1,0),(2,0),(3,0)], # ㅣ
[(0,0),(1,0),(0,1),(1,1)], # ㅁ
[(0,0),(1,0),(2,0),(2,1)], # ㄴ
[(1,0),(1,1),(1,2),(0,2)],
[(0,0),(0,1),(1,1),(2,1)],
[(0,0),(0,1),(0,2),(1,0)],
[(2,0),(2,1),(1,1),(0,1)],
[(0,0),(0,1),(0,2),(1,2)],
[(0,0),(0,1),(1,0),(2,0)],
[(0,0),(1,0),(1,1),(1,2)],
[(0,0),(1,0),(1,1),(2,1)], # ㄴㄱ
[(1,0),(1,1),(0,1),(0,2)],
[(0,1),(2,0),(1,1),(1,0)],
[(0,0),(0,1),(1,1),(1,2)],
[(0,1),(1,0),(1,1),(1,2)], # ㅗ
[(1,0),(0,1),(1,1),(2,1)],
[(0,0),(0,1),(0,2),(1,1)],
[(0,0),(1,0),(1,1),(2,0)]]
n,m = map(int, sys.stdin.readline().rstrip().split())
board = []
result = 0
for _ in range(n):
board.append(list(map(int,sys.stdin.readline().rstrip().split())))
for i in range(n): # 열 이동
for j in range(m): # 행 이동
for tetromino in tetrominos: # 19개의 테트로미노에서 하나씩 선택
temp = 0
for dx,dy in tetromino: # 기준 좌표 board[i][j]에서 테트로미노에 맞게 dx,dy 좌표 더해줌
ix = i + dx
jy = j + dy
if 0 <= ix < n and 0 <= jy < m:
temp += board[ix][jy]
else: # 범위를 넘어가면 result 로 채택될 수 없도록 -inf 값 지정
temp = -(math.inf)
break
if result < temp: # 테트로미노 하나씩 마다 result 갱신가능 여부 판단
result = temp
print(result)
3. Learned
-前述したように、サイズ比較による分岐
-各行に3を追加したボードに-inf値を追加し、結果として使用しないようにします.
-exceptionを使用して
No. 1748
1. Problem
2. My Solution
import sys
n = sys.stdin.readline().rstrip()
count = [0,9,180,2700,36000,450000,5400000,63000000,720000000]
res = 0
if len(n) == 1:
print(n)
else:
for i in range(1,len(n)):
res += count[i]
res += (int(n) - int('9' * (len(n) - 1))) * len(n)
print(res)
3. Others' Solutions import sys
n = sys.stdin.readline().rstrip()
res = 0
for i in range(len(n)-1):
res += 9 * (10 ** i) * (i+1)
print(res + ((int(n) - (10 ** (len(n)-1)) + 1) * len(n)))
4. Learned (10*i)原理を用いて
No. 15649
1. Problem
2. My Solution
したがって、arr値を変更するたびに、resリストの要素(res[index])も変更値を示す.
import sys
def permutation(level):
if level >= m:
res.append(arr)
else:
for i in range(1, n+1):
if visited[i] == True:
continue
else:
arr[level] = i
visited[i] = True
permutation(level+1)
visited[i] = False
n, m = map(int,sys.stdin.readline().rstrip().split())
visited = [False] * (n+1)
arr = [0] * m
res = []
permutation(0)
for i in res:
print(' '.join(map(str,i)))
import sys
def permutation(level):
if level >= m:
res.append(arr.copy())
else:
for i in range(1, n+1):
if visited[i] == True:
continue
else:
arr[level] = i
visited[i] = True
permutation(level+1)
visited[i] = False
n, m = map(int,sys.stdin.readline().rstrip().split())
visited = [False] * (n+1)
arr = [0] * m
res = []
permutation(0)
for i in res:
print(' '.join(map(str,i)))
3. Others' Solutions
4. Learned Reference
この問題について(BAEKJOON : 14500, 1748, 15649), 我々は、より多くの情報をここで見つけました https://velog.io/@codren/BAEKJOON-14500テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol