코딩테스트 11

[백준] 13305번 : 주유소 (python 파이썬)

https://www.acmicpc.net/problem/13305  from collections import dequeimport sysn = int(input())road = list(map(int, sys.stdin.readline().split(" "))) #도로의 길이oil = list(map(int, sys.stdin.readline().split(" "))) # 주유소의 기름 가격graph = [[oil[0],0]] #[기름가격의 최솟값, 주요소까지의 거리]min_oil = oil[0]length = 0for i in range(len(road)): if oil[i] = length: print(cost) break if oil  문제 설명n개의 도시가 ..

[프로그래머스] 양과 늑대 [Level 3] (python 파이썬)

https://school.programmers.co.kr/learn/courses/30/lessons/92343 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr    from collections import dequedef solution(info, edges): visit = [0 for i in range(len(info))] graph = [[] for i in range(len(info))] for edge in edges: graph[edge[0]].append(edge[1]) visit[0] = 1..

[프로그래머스] 다단계 칫솔 판매 [Level 3] (python 파이썬)

https://school.programmers.co.kr/learn/courses/30/lessons/77486 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr       def solution(enroll, referral, seller, amount): d = {} graph = {} for i in range(len(referral)): d[enroll[i]] = referral[i] graph[enroll[i]] = 0 s = [] for i in range(len(amount)): s...

[프로그래머스] 베스트앨범[Level 3] (python 파이썬)

https://school.programmers.co.kr/learn/courses/30/lessons/42579 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr def solution(genres, plays): d1 = {} d2 = {} s = {} for i in range(len(plays)): if genres[i] not in s: s[genres[i]] = plays[i] else: s[genres[i]] += plays[i] ..

[프로그래머스] 여행경로 [Level 3] (python 파이썬) [BFS]

https://school.programmers.co.kr/learn/courses/30/lessons/43164 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr     from collections import dequedef solution(tickets): d= deque() n = len(tickets) for i in range(n): if tickets[i][0] == "ICN": visit = [0 for i in range(n)] visit..

[프로그래머스] 단어 변환 [Level 3] (python 파이썬) [DFS/BFS]

https://school.programmers.co.kr/learn/courses/30/lessons/43163 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr       from collections import dequedef checkdiff(s1, s2): n = 0 for i in range(len(s1)): if s1[i] != s2[i]: n += 1 if n > 1: return 0 if n ==1: ..

[백준] 21736번 : 헌내기는 친구가 필요해 [BFS 설명 有]

https://www.acmicpc.net/problem/21736 21736번: 헌내기는 친구가 필요해2020년에 입학한 헌내기 도연이가 있다. 도연이는 비대면 수업 때문에 학교에 가지 못해 학교에 아는 친구가 없었다. 드디어 대면 수업을 하게 된 도연이는 어서 캠퍼스 내의 사람들과 친해지고www.acmicpc.net        import sysfrom collections import deque n, m = map(int, sys.stdin.readline().split(" "))l = []a,b = 0, 0for i in range(n): l2 = list(sys.stdin.readline().strip()) if 'I' in l..

[백준] 14940번 : 쉬운 최단거리 (python 파이썬)

https://www.acmicpc.net/problem/14940 14940번: 쉬운 최단거리지도의 크기 n과 m이 주어진다. n은 세로의 크기, m은 가로의 크기다.(2 ≤ n ≤ 1000, 2 ≤ m ≤ 1000) 다음 n개의 줄에 m개의 숫자가 주어진다. 0은 갈 수 없는 땅이고 1은 갈 수 있는 땅, 2는 목표지점이www.acmicpc.net  처음에는     import sysdef func(x,y): if y+1 = 0: if l[x][y-1] == 1: l[x][y-1] = l[x][y] +1 return func(x,y-1) elif l[x][y]+1 = 0: ..

[백준] 2630번 : 색종이 만들기 (python 파이썬)

https://www.acmicpc.net/problem/2630 2630번: 색종이 만들기첫째 줄에는 전체 종이의 한 변의 길이 N이 주어져 있다. N은 2, 4, 8, 16, 32, 64, 128 중 하나이다. 색종이의 각 가로줄의 정사각형칸들의 색이 윗줄부터 차례로 둘째 줄부터 마지막 줄까지 주어진다.www.acmicpc.net  아주 깔끔한 문제인 거 같다.  문제를 읽고 직관적으로 바로 이해되는 문제가 나는 가장 좋은 문제라고 생각한다.  이 문제는 저번에 포스팅했었던 1074번 Z 문제와 흡사하다.https://mail-study.tistory.com/12 [백준] 1074번 : Z (python 파이썬)https://www.acmicpc.net/pr..

[프로그래머스] 메뉴 리뉴얼 [Level 2] (python 파이썬)

https://school.programmers.co.kr/learn/courses/30/lessons/72411 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr        from itertools import combinationsdef solution(orders, course): ans = [] for i in course: d = {} for order in orders: for com in list(combinations(order, i)): ..

반응형