본문 바로가기

코딩테스트

(61)
[Python] 백준 코테 연습 - DP (2) DP 이어서 BABBA - 실버5https://www.acmicpc.net/problem/9625K = int(input())DP_B = [0] *(K+1) # 1, 0, 1, 1, 2DP_BA = [0] *(K+1) # 0, 1, 1, 2, 3DP_B[1] = 1for i in range(2, K+1): DP_BA[i] = DP_B[i-1] + DP_BA[i-1] DP_B[i] = DP_BA[i-1] print(DP_BA[K], DP_B[K]+DP_BA[K])  카드 구매하기2 - 실버 1https://www.acmicpc.net/problem/16194import sysinput = sys.stdin.readlineN = int(input())P = [0] + list(map(int, i..
[Python] 백준 코테 연습 - DP (1) DP 어려워서 추가 연습중 가장 큰 증가하는 부분 수열 - 실버2https://www.acmicpc.net/status?user_id=jain5379&problem_id=11055&from_mine=1import sysinput = sys.stdin.readlineA = int(input())num = list(map(int, input().split()))DP = [0]*A # 합이 가장 큰 증가하는 수열 저장DP[0] = num[0]max_value = 0for i in range(A): for j in range(i): if num[i] > num[j]: DP[i] = max(DP[j] + num[i], DP[i]) else: ..
[Python] 백준 코테 연습 - DFS 연결 요소의 개수 - 실버2https://www.acmicpc.net/problem/11724import syssys.setrecursionlimit(10000) # 재귀 최대 깊이 설정input=sys.stdin.readlineN, M = map(int, input().split())A = [[] for _ in range(N+1)] # 그래프 데이터 저장 리스트visited = [False]*(N+1)def DFS(v): visited[v] = True for i in A[v]: if not visited[i]: DFS(i)for _ in range(M): s, e = map(int, input().split()) A[s].append(e) ..
[Python] 백준 코테 연습 - Prefix Sum(누적합) 귀찮아 - 실버5https://www.acmicpc.net/problem/14929# 처음 풀이.. N^2 시간 초과N = int(input())num = list(map(int, input().split()))ans = 0for i in range(N-1): for j in range(i+1, N): a = num[i]*num[j] ans += aprint(ans)N = int(input())num = list(map(int, input().split()))temp = []temp.append(num[0])for i in range(1, N): temp.append(temp[i-1] + num[i]) # temp = [X1, X1+X2, X1+X2+X3, ... ]..
[Python] 백준 코테 연습 - 자료구조 큐 - 실버4https://www.acmicpc.net/problem/10845import queueq = queue.Queue()for _ in range(int(input())): a = list(input().split()) if a[0]=='push': q.put(int(a[1])) elif a[0]=='front': if q.empty(): print(-1) else: print(q.queue[0]) elif a[0]=='back': if q.empty(): print(-1) else: print(q.queue[-1]) elif ..
[Python] 백준 코테 연습 - 구현 소가 길을 건너간 이유 - 브론즈 1https://www.acmicpc.net/problem/14467N = int(input())cow = {}ans = 0for _ in range(N): a, b = map(int, input().split()) if a in cow: if cow[a] != b: cow[a] = b ans += 1 else: cow[a] = bprint(ans)  전구 - 브론즈 2https://www.acmicpc.net/problem/21918N, M = map(int, input().split())bolt = list(map(int, input().split()))for _ in range(M): ..
[Python] 백준 코테 연습 - 문자열 문제 참고한 사이트https://codingdodo.tistory.com/94 백준 코딩테스트 초보 추천 문제 모음(브론즈~골드3)백준에서 코딩테스트 초보 단계에서 풀어가면 괜찮지 않을까 싶은 문제들을 종합해 놓은 페이지입니다. 파이썬, C++, 자바 등 여러 언어들이 지원되는 사이트지만 저는 자바로 문제들을 풀어나codingdodo.tistory.com  복호화 - 브론즈2 https://www.acmicpc.net/problem/9046original_text = "abcdefghijklmnopqrstuvwxyz"encoding_text = "wghuvijxpqrstacdebfklmnoyz"for i in range(int(input())): text = str(input()).replace('..
[Python] 다양한 문제 풀어보기 동아리 마지막 과제여러 문제 풀어보기!  https://www.acmicpc.net/workbook/view/8708여기에 있는 다양한 유형의 문제들을 풀어본다.https://www.acmicpc.net/problem/23971import sysinput = sys.stdin.readline# 예제 : 10 10 2 2 -> 16# 예제 : 50000 50000 11 9 -> 20835000H, W, N, M = map(int, input().split()) a = H//(N+1)if H%(N+1)!=0: a+=1b = W//(M+1)if W%(M+1)!=0: b+=1print(a*b)단순 사칙연산 문제.나는 if문을 이용했지만, 그냥 나누기 연산 후 반올림을 해주는게 편할 듯 https://..