분류 전체보기 288

[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..

[Python][백준] 10655. 마라톤 1/ 구현, 브루트포스 (S3)

링크🔗https://www.acmicpc.net/problem/10655🗒️파이썬 코드 풀이N = int(input())x_lst = []y_lst = []for _ in range(N): x,y = map(int,input().split()) x_lst.append(x) y_lst.append(y)sum = 0 for i in range(0,len(x_lst)-1): sum = sum + abs(x_lst[i]-x_lst[i+1]) + abs(y_lst[i]-y_lst[i+1])mn = 1e100for i in range(1,len(x_lst)-1): prev_mid = abs(x_lst[i-1] - x_lst[i]) + abs(y_lst[i-1] - y_lst[i]) ..

[Python][백준] 2583. 영역 구하기/ 그래프 탐색,DFS,BFS (S1)

링크🔗https://www.acmicpc.net/problem/2583🗒️파이썬 코드 풀이 (DFS)import syssys.setrecursionlimit(10**6)input = sys.stdin.readlineN, M, K = map(int, input().split())lst = [[0] * M for _ in range(N)]for _ in range(K): j1, i1, j2, i2 = map(int, input().split()) for i in range(i1, i2): for j in range(j1, j2): lst[i][j] = 1 di, dj = [0, -1, 0, 1], [1, 0, -1, 0]rs = []def d..

[Python][백준] 11724. 연결 요소의 개수/ 그래프 탐색,DFS,BFS (S2)

링크🔗https://www.acmicpc.net/problem/11724🗒️파이썬 코드 풀이 (DFS)import syssys.setrecursionlimit(10**6)input = sys.stdin.readlinedef dfs(graph,i,visited): visited[i] = True for v in graph[i]: if not (visited[v]): dfs(graph,v,visited)N, M = map(int, input().split())graph = [[] for _ in range(N + 1)]visited = [0] * (N + 1)for _ in range(M): u, v = map(int, input().split()) ..

[Python][백준] 18429. 근손실 / 브루트포스,백트래킹 (S3)

링크🔗https://www.acmicpc.net/problem/18429🗒️파이썬 코드 풀이 (순열)from itertools import permutationsN,K = map(int,input().split())lst = list(map(int,input().split()))comb_lst = list(permutations(lst))rs = 0for c_ls in comb_lst: total = 500 cnt = 0 for c in c_ls: total += (c-K) if total  1. 순열로 푸는 방식은 간단하다. 그냥 모든 조합을 반복문 돌리면 된다. 2. itertools 라이브러리를 호출해서 permutations 함수를 호출 (조합은 c..

[Python][백준] 1935. 후위 표기식2 / 자료,구조스택 (S3)

링크🔗https://www.acmicpc.net/problem/1935🗒️파이썬 코드 풀이N = int(input())lst = list(input())num_lst = [int(input()) for _ in range(N)]stack = []for ls in lst : if "A"  1. 후위 표기식은 스택 구조로 풀이한다. 2. 리스트는 세개를 선언해주었다 . (후위 표기식, 입력값들, 스택) 3. 입력값들로 반복문을 돌리고, 알파벳과 연산자를 구분한다.- 알파벳 같은 경우 stack에 넣어준다- 연산자 같은 경우 stack에서 2개를 pop해주고, 해당 연산자로 계산한다.(뒤 늦게 pop 된 것이 stack1이 되고, 처음으로 pop 된 것은 stack2가 된다.) 4. 문자열 형식 지정..

[Python][백준] 15989. 1, 2, 3 더하기 4 / 구현(S3)

링크🔗https://www.acmicpc.net/problem/16967🗒️파이썬 코드 풀이H,W,X,Y = map(int,input().split(" "))lst_b = [list(map(int,input().split(" "))) for _ in range(H+X)]for h in range(H): for w in range(W): lst_b[h+X][w+Y] = lst_b[h+X][w+Y] - lst_b[h][w] print(lst_b[h][w], end=" ") print() 1. 단순 구현 문제이다.  2. 배열  A의 크기는 H,W이고, A에서 (X,Y) 만큼 이동 한 것을 합한게 B 이므로,합쳐지는 과정에 겹치는 것을 빼주면 된다. ex) H =2, W..