[Baekjoon] 1025. 제곱수 찾기
·
코딩테스트/Python
🔗 Problem Linkhttps://www.acmicpc.net/problem/1025❔Thinking주어진 표에서, 일정한 간격으로 이동하며 숫자를 선택해 완전 제곱수를 만든다.만들 수 있는 완전 제곱수 중 가장 큰 수를 반환한다. 완전 제곱수를 만들 수 없는 경우 -1을 반환한다.완전 제곱수는 어떤 정수를 제곱한 수이다.💻Solutionimport sys, mathinput = sys.stdin.readlineN, M = map(int, input().split())board = [list(input().rstrip()) for _ in range(N)]def check(num: int): return math.isqrt(num) ** 2 == numanswer = set()for row..
[Baekjoon] 1202. 보석 도둑
·
코딩테스트/Python
🔗 Problem Linkhttps://www.acmicpc.net/problem/1202❔Thinking보석의 무게와 가격이 주어질 때, 가방에 보석 하나씩만을 담아 최대 가격을 반환한다.💻Solutionimport heapqimport sysinput = sys.stdin.readlineN, K = map(int, input().split())jewels = []bags = []for _ in range(N): weight, value = map(int, input().split()) jewels.append((weight, value))for _ in range(K): bags.append(int(input()))jewels.sort() bags.sort()max_heap = [..
[Baekjoon] 2493. 탑
·
코딩테스트/Python
🔗 Problem Linkhttps://www.acmicpc.net/problem/2493❔Thinking탑의 높이가 주어진 배열에서, 현 위치 왼쪽에 위치한 높은 탑의 가장 가까운 위치를 담아 반환한다.동일한 높이의 탑도 포함하여 확인한다.결국, 자신보다 높지 않은 탑은 비교 대상에서 제외된다.💻Solutionimport sysinput = sys.stdin.readlineN = int(input().rstrip())buildings = list(map(int, input().split()))laser = [0] * Nstack = [(0,0)] # (위치, 높이)for idx, height in enumerate(buildings): while stack and stack[-1][1] 🗝️..
[Programmers] Level 2. 요격 시스템
·
코딩테스트/Python
🔗 Problem Link 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr❔Thinking개구간 (s, e)들이 주어질 때, 모든 구간을 통과하는 막대의 최소 개수를 반환한다.s나 e에서는 해당 구간을 통과할 수 없다. 💻Solutiondef solution(targets): answer = 0 targets = sorted(targets, key=lambda x: x[1]) e = 0 for i in range(len(targets)): if targets[i][0] >= e: answer += 1 e = targets[i][..
[Baekjoon] 1101. Fly me to the Alpha Centauri
·
코딩테스트/Python
🔗 Problem Linkhttps://www.acmicpc.net/problem/1011❔Thinkingx,y 두 좌표가 주어지면, x에서 y로 가는 최소 이동 횟수를 반환한다.이전에 k번 이동했다면, 다음은 k-1, k, k+1를 이동할 수 있다.y에 도착하는 이동은 1이어야 한다.💻Solutiondef alpha_centauri(x, y): distance = y - x move = 0 step = 1 total_moved = 0 while total_moved 🗝️keypoint최소한으로 이동하기 위해서는 점차 이동 거리를 늘려야 하고, y에 1을 이동하여 도착하기 위해서는 이동 거리를 점차 줄여나가야 한다. (ex - 1, 2, 3, 2, 1)같은 거리의 이동이 ..
[Beakjoon] 9663. N-Queen
·
코딩테스트/Python
🔗 Problem Linkhttps://www.acmicpc.net/problem/9663❔Thinking체스판의 퀸의 이동경로가 겹치지 않도록 N개를 놓는 방법의 수를 구한다.퀸은 상하좌우, 대각선 모두를 이동할 수 있다.💻Solutionn = int(input())def put_queen(row:int): global left_right, yx, y_x, cnt, n if row == n: cnt += 1 return for i in range(n): if left_right[i] is False and yx[row+i] is False and y_x[(n-1) + row-i] is False: left_right[i] = ..