본문 바로가기

전체 글

(261)
[백준] 1743 : 음식물 피하기 python NxM 크기의 그래프를 만들고 음식물쓰레기가 있는 자리는 1로 표시한다. 그리고 그래프에서 아직 미방문이면서 음식물쓰레기가 있는 자리에서부터 BFS나 DFS를 수행하면서 쓰레기의 크기를 cnt_list에 추가해줬다. 모든 탐색이 끝나고나서 max(cnt_list)를 출력해주면 된다. from collections import deque import sys input = sys.stdin.readline def bfs(a,b): q = deque() q.append((a,b)) visited[a][b] = 1 cnt = 1 while q: x,y = q.popleft() for i in range(4): nx = x+dx[i] ny = y+dy[i] # 미방문이면서 음식물쓰레기가 있는 자리라면 큐에 넣고 ..
[백준] 7562 : 나이트의 이동 python from collections import deque import sys input = sys.stdin.readline def bfs(a,b): q = deque() q.append((a,b)) while q: x,y = q.popleft() if x==d_x and y==d_y: # 목적지까지의 이동횟수 출력 return board[x][y] for i in range(8): nx,ny = x+dx[i],y+dy[i] # 이동할 수 있다면 board에 이동횟수를 기록하고, 큐에 넣음 if 0
[SWEA/D3] 16800 : 구구단 걷기 python https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AYaf9W8afyMDFAQ9 SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com i가 2부터 시작하고 num이 40일 때 나올 수 있는 i,j의 순서쌍은 (2, 20), (4, 10), (5, 8), (8, 5), (10, 4), (20, 2)이다. 이중에서 최단거리에 있는 것은 i+j가 최소인 순간인 (5,8) 또는 (8,5)일 때이다. 그런데 생각해보면 (5, 8)일 때 이후로는 구할 필요가 없다. 순서쌍의 앞뒤값의 순서가 달라지기만 할 뿐이기 때문이다. 따라서 i가 num..
[SWEA/D4] 2819 : 격자판의 숫자 이어 붙이기 python https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=4&contestProbId=AV7I5fgqEogDFAXB&categoryId=AV7I5fgqEogDFAXB&categoryType=CODE&problemTitle=&orderBy=SUBMIT_COUNT&selectCodeLang=PYTHON&select-1=4&pageSize=10&pageIndex=1&&&&&&&&&& SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 35분만에 풀었다. 뿌듯 from collections import deque T = int(input()) ..
[SWEA/D3] 13218 : 조별과제 python https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AXzjvCCq-PwDFASs&categoryId=AXzjvCCq-PwDFASs&categoryType=CODE&problemTitle=&orderBy=PASS_RATE&selectCodeLang=ALL&select-1=3&pageSize=10&pageIndex=1 SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 난이도 책정이 잘못된 문제인 듯하다. n을 3으로 나눈 몫을 출력해주기만 하면 된다. T = int(input()) for test_cas..
[SWEA/D2] 1288 : 새로운 불면증 치료법 python https://swexpertacademy.com/main/code/problem/problemDetail.do T = int(input()) for test_case in range(1, T + 1): N = input() tmp = N s = set() while True: for c in tmp: if int(c) not in s: s.add(int(c)) if len(s)==10: print('#%d'%test_case,tmp) break tmp = str(int(tmp)+int(N)) 음...형변환을 많이 써서 자칫하면 실수하면 딱 좋겠다는 느낌이 든다. 리스트를 쓰면 더 간략하게 풀 수 있을 것 같으니 생각을 좀 해봐야겠다. 수정한 코드 T = int(input()) for test_case ..
[SWEA/D2] 1284 : 수도 요금 경쟁 python https://swexpertacademy.com/main/code/problem/problemDetail.do T = int(input()) for test_case in range(1, T + 1): P,Q,R,S,W = map(int,input().split()) A = W*P B = Q if W>R: B += (W-R)*S print('#%d'%test_case,min(A,B))
[SWEA/D2] 1948 : 날짜계산기 python https://swexpertacademy.com/main/code/problem/problemDetail.do 우선 각 달의 일수를 days라는 list에 저장한다. 5/5와 8/15가 주어졌다고 했을 때 days[5]+days[6]+days[7]+d2-d1를 계산해주면 된다. T = int(input()) days = [0,31,28,31,30,31,30,31,31,30,31,30,31] for test_case in range(1, T + 1): m1, d1, m2, d2 = map(int,input().split()) total = 1 for i in range(m1,m2): total += days[i] total = total-d1+d2 print('#%d'%test_case,'%d'%total)