♟️ 알고리즘 117

[Python][백준] 1449. 수리공 항승 / 정렬,그리디(S3)

링크🔗https://www.acmicpc.net/problem/1449🗒️파이썬 코드 풀이N,L = map(int,input().split())lst = list(map(int,input().split()))lst.sort()start = lst[0]-1end = start + L count = 1for i in range(N): if lst[i]  1. 입력받은 lst를 정렬 해준다. 2. Start와 end의 범위를 만들어주고, 범위를 갱신하는 방향으로 간다. 3. 반복문에서 lst[i]가 Start와 end의 범위 내외면 continue,lst[i]가 Start와 end의 범위 밖이면 범위 초기화 및 count + 1   🗒️내 풀이 코드from collections import dequ..

[Python][백준] 7562. 나이트의 이동/ BFS,그래프 탐색(S1)

링크🔗https://www.acmicpc.net/problem/7562🗒️파이썬 코드 풀이from collections import dequeT = int(input())for _ in range(T): I = int(input()) start_x,start_y = list(map(int,input().split())) end_x,end_y = list(map(int,input().split())) chess = [[-1]*I for _ in range(I)] nights = [[-2,-1],[-2,1],[2,1],[2,-1],[-1,2],[1,2],[-1,-2],[1,-2]] def dfs(i,j): q = deque([[i,j]]) ches..

[Python][백준] 1931. 회의실 배정/ 그리디,정렬(S1)

링크🔗https://www.acmicpc.net/problem/1931🗒️파이썬 코드 풀이N = int(input())lst = []for _ in range(N): start,end = map(int,input().split()) lst.append((start,end))lst.sort()rs_lst = [lst[0]]for i in range(1,N): if rs_lst[-1][1] > lst[i][0]: if rs_lst[-1][1] > lst[i][1]: rs_lst.pop() rs_lst.append(lst[i]) elif rs_lst[-1][1]  1. 먼저 마구잡이의 입력을 (strart 기준)정렬해준다.  2. 비..

[Python][백준] 2589. 보물섬 / 브루트포스,BFS (G5)

링크🔗https://www.acmicpc.net/problem/2589🗒️파이썬 코드 풀이from collections import deque import syssys.setrecursionlimit(10**6)input = sys.stdin.readlineN,M = map(int,input().split())graph = [list(input().strip()) for _ in range(N)]visited = [[-1] * M for _ in range(N)]ans = -1di,dj = [0,1,0,-1],[1,0,-1,0]def bfs(i,j): global ans visited = [[-1] * M for _ in range(N)] visited[i][j] = 0 q = ..

[Python][백준] 2529. 부등호 / 브루트포스,백트래킹 (S1)

링크🔗https://www.acmicpc.net/problem/2529🗒️파이썬 코드 풀이import syssys.setrecursionlimit(10**6)input = sys.stdin.readlineK = int(input())lst = list(input().strip())lst = list(filter(lambda x : x != " ", lst))rs_lst = []visited = [0] * 10def get_num(a,b,sign): if sign == " b : return True return Falsedef dfs(n,result): if n == K+1 : rs_lst.append(result) return for i in ..

[Python][백준] 2621. 카드 게임 / 빡구현 (S3)

링크🔗https://www.acmicpc.net/problem/2621🗒️파이썬 코드 풀이lst = []for _ in range(5): C,N = input().split(" ") N = int(N) lst.append((C,N))lst = sorted(lst,key=lambda x:x[1])rs = 0# 연속성 확인def chk_sequence(): sequence = True for i in range(len(lst)) : if lst[0][1] + i != lst[i][1]: sequence = False return sequence return sequence# 색상 같음 확인 def chk_same_colo..