백준
-
[백준] 4796번 캠핑 - 그리디 알고리즘Algorithm/1일 1코테 2021. 8. 11. 18:37
https://www.acmicpc.net/status?user_id=kimdi96&problem_id=4796&from_mine=1 채점 현황 www.acmicpc.net 처음 단순하게 생각한 답....! 그런데 찾아보니 예외가 있더라 for i in range(1,999): L,P,V = map(int, input().split()) if L == 0 and P == 0 and V == 0: break answer= (V//P)*L + (V%P) print("Case", i, ":", answer) 예외처리를 해줬다! for i in range(1,999): L,P,V = map(int, input().split()) if L == 0 and P == 0 and V == 0: break answer=..
-
[🥲 백준] 11724번 연결요소의 개수 - BFS/DFS카테고리 없음 2021. 8. 9. 21:16
https://www.acmicpc.net/problem/11724 11724번: 연결 요소의 개수 첫째 줄에 정점의 개수 N과 간선의 개수 M이 주어진다. (1 ≤ N ≤ 1,000, 0 ≤ M ≤ N×(N-1)/2) 둘째 줄부터 M개의 줄에 간선의 양 끝점 u와 v가 주어진다. (1 ≤ u, v ≤ N, u ≠ v) 같은 간선은 한 번만 주 www.acmicpc.net 🍪 내 풀이 # 시간 초과 import sys a,b = map(int,sys.stdin.readline().split()) connect_graph = {i:[] for i in range(1, a+1)} # 연결관계 그래프 # 그래프에 값을 넣어줌 for _ in range(b): c,d = map(int,sys.stdin.read..
-
[🐉 백준 13단계] 백트래킹Algorithm/1일 1코테 2021. 1. 4. 15:45
백트래킹: 조건에 따른 모든 조합의 수를 찾는 것. 15649 import itertools a, b = input().split() l = [i for i in range(1, int(a)+1)] s = list(itertools.permutations(l, int(b))) for s in s: a = '' for i in s: a += str(i) a += ' ' print(a) 15650 import itertools a, b = input().split() l = [i for i in range(1, int(a)+1)] s = list(itertools.combinations(l, int(b))) for s in s: a = '' for i in s: a += str(i) a += ' ' prin..
-
[🐉 백준 12단계] 정렬Algorithm/1일 1코테 2020. 12. 21. 14:43
백준 12단계 [정렬] 2750 n = int(input()) a = [] for _ in range(n): a.append(int(input())) a.sort() for i in range(len(a)): print(a[i]) 2751 import sys n = int(input()) l = [] for _ in range(n): l.append(int(sys.stdin.readline())) l.sort() for i in l: print(i) 10989 import sys c = [0] * 10001 n = int(input()) for _ in range(n): a = int(sys.stdin.readline()) c[a] += 1 for i in range(len(c)): if c[i] != ..
-
[🐉 백준 11단계] 브루트 포스Algorithm/케로베로스 2020. 12. 21. 14:43
백준 11단계 브루트 포스 2798 n, s = map(int, input().split()) l = list(map(int, input().split())) m = 0 while l: a = l.pop(0) for i in range(len(l)-1): for j in range(i+1, len(l)): if a+l[i]+l[j] m: m = a+l[i]+l[j] print(m) 2231 n = int(input()) idx = 0 for i in range(1, n+1): l = list(map(int, str(i))) s = i + sum(l) if n == s: idx = i break print(idx) 7568 n = int(input()) d = [] answer = [] for _ in r..
-
[🐉 백준 9단계] 수학 2Algorithm/케로베로스 2020. 12. 13. 22:55
백준 9단계 수학 2 1978 n=input() l=list(map(int, input().split())) answer = 0 for i in l: count = 0 for j in range(1, i+1): if i == 1: break if i%j == 0: count += 1 if count == 2: answer += 1 print(answer) 2581 import math while True: n = int(input()) if n == 0: break count = 0 for i in range(n+1, 2*n+1): if i == 1: continue elif i == 2: count += 1 continue else: for j in range(2, int(math.sqrt(i))+1)..
-
[🐉 백준 8단계] 수학 1Algorithm/케로베로스 2020. 12. 13. 20:11
백준 8단계 수학 1 1712 a, b, c = map(int, input().split()) if b >= c: print(-1) else: print(int(a/(c-b))+1) 2839 n = int(input()) count = 0 while True: if (n % 5) == 0: count = count + (n//5) print(count) break n = n-3 count += 1 if n < 0: print("-1") break 2292 n = int(input()) a = 2 b = 1 for i in range(0, n): if n == 1: print(1) break a = a + 6*i b = b + 6*(i+1) if a