본문 바로가기

문제풀이66

[백준✨] 1992번 <쿼드트리> / Python 문제풀이 / 해답) import sys def input(): return sys.stdin.readline() N = int(input()) board = [] for _ in range(N): board.append(list(input())) def isAllSame(s_r, s_c, n): chk = board[s_r][s_c] for i in range(n): for j in range(n): if board[s_r+i][s_c+j] != chk: return False return True def do(s_r, s_c, n): if n == 1: return board[s_r][s_c] if isAllSame(s_r,s_c, n): return board[s_r][s_c] l_u = str(do(s_r, s.. 2020. 10. 27.
[백준✨] 1780번 <종이의 개수> / Python 문제풀이 해답) import sys sys.setrecursionlimit(10**8) def input(): return sys.stdin.readline().rstrip() N = int(input()) board = [] result = [0, 0, 0] for _ in range(N): board.append(list(map(int, input().split()))) # 종이가 조건에 맞는지 def isEnd(board, s_r, s_c, length): v = board[s_r][s_c] for i in range(s_r, s_r + length): for j in range(s_c, s_c + length): if board[i][j] != v: return False return True # 분할 d.. 2020. 10. 2.
[백준✨] 10825번 <국영수> / Python 문제풀이 해답) import sys def input(): return sys.stdin.readline().rstrip() scores = [] for _ in range(int(input())): name, kor, eng, math = input().split() kor, eng, math = map(int, [kor, eng, math]) ''' 정렬의 우선순위는 1. 국어 내림차순 2. 영어 오름차순 3. 수학 내림차순 4. 이름 오름차순 이 순서에 맞게 튜플 형태로 리스트에 넣어준다. ''' scores.append((kor, eng, math, name)) result = sorted( scores, key=lambda score: (-score[0], score[1], -score[2], score.. 2020. 9. 22.
[백준✨] 1106번 <제곱ㄴㄴ수> / Python 문제풀이 해답) import sys import math def input(): return sys.stdin.readline().rstrip() MIN, MAX = map(int, input().split()) last = int(math.floor(math.sqrt(MAX))) # 마지막 후보 제곱수, MAX보다 작은 last*last ''' MIN 부터 MAX까지 아리스토 체를 구현한다. res[0] == res[MIN] 이걸 의미하게 하기 위해 넣어줄 떄 res[n-MIN] 을 해준다. ''' res = [True for i in range(MAX-MIN+1)] for i in range(2, last+1): zegop = i * i mok = MIN // zegop # 몫을 1씩 높여주며 걸러준다. wh.. 2020. 9. 15.
[백준✨] 3344번 < N-Queen > / Python 문제풀이 / 해답) N = int(input()) ''' 알고리즘의 출처 : https://en.wikipedia.org/wiki/Eight_queens_puzzle 위키 설명 읽고 그대로 코드로 옮겼습니다. The examples above can be obtained with the following formulas.[3] Let (i, j) be the square in column i and row j on the n × n chessboard, k an integer. One approach[3] is 1. If the remainder from dividing n by 6 is not 2 or 3 then the list is simply all even numbers followed by all odd .. 2020. 8. 7.
[백준] 11650번 . 좌표 정렬하기 ✨ / Python 문제풀이 / 함수형 프로그래밍 해답) # x, y 를 튜플형태로 입력받아 리스트로 만든다. => xys xys = [tuple(map(int, input().split())) for _ in range(int(input()))] # 튜플을 받아 원하는 포맷으로 바꿔준다. # 예) (1, 1) => "1 1" 로 바꿔준다. def toAnswerFormat(tup): x, y = tup return str(x) + " " + str(y) # xys 를 문제에 맞는 조건으로 정렬한다. xys = sorted(xys, key=lambda tu: (tu[0], tu[1])) # map(fun, xys) 을 통해 xys 의 모든 원소들을 맞는 포맷으로 바꿔주고, # "\n".join() 을 통해 줄바꿈으로 묶어준다. result = "\n"... 2020. 8. 5.