목록분류 전체보기 (132)
토니의 연습장
sentence1 = "안녕하세요? 반갑습니다."sentence2 = "안녕하세요? 반갑습니다!"sentence3 = "안녕하세요? 만나서 반가워요."sentence4 = "Hi, nice to meet you."sentence5 = "I like to eat apples."from sklearn.metrics.pairwise import cosine_similaritysentences = [sentence1, sentence2, sentence3, sentence4, sentence5]embedded_sentences = embeddings.embed_documents(sentences)def similarity(a, b): return cosine_similarity([a], [b])[0][0]..
https://www.acmicpc.net/problem/2252from collections import dequeN, M = list(map(int, input().split()))adj = [[] for _ in range(N)]need_to_learn = [0]*Nfor _ in range(M): a,b = list(map(int, input().split())) adj[a-1].append(b-1) need_to_learn[b-1] += 1 # 위상 정렬queue = deque([]) # 처리 가능 목록for i in range(N): if need_to_learn[i] == 0: queue.append(i) # 리스트에 쌓아두고 하나씩 처리 위함 ..
https://www.acmicpc.net/problem/1463N = int(input())a = [0]*(N+1) # 길이 N+1, a[N] 참조 가능a[1] = 0for i in range(2, N+1): a[i] = 1+a[i-1] if i%3 == 0: a[i] = min(a[i], 1+a[i//3]) if i%2 == 0: a[i] = min(a[i], 1+a[i//2]) print(a[N]) https://www.acmicpc.net/problem/2579N = int(input())S = [0]*Nfor i in range(N): S[i] = int(input())A = [0]*NB = [0]*NA[0] = S[0]B[0] ..
https://www.acmicpc.net/problem/5525N = int(input())M = int(input())S = input()# 해쉬 값 계산 위한 준비mod = 1e9 + 7 # 10억 7 (큰 소수)po = [0]*Mpo[0] = 1for i in range(1,M): po[i]=po[i-1]*31 % mod# PnPn = "I"for i in range(N): # O가 N개 Pn += "OI" K = len(Pn)# Pn의 해쉬 값 계산Pn_hash = 0for i in range(K): Pn_hash *= 31 Pn_hash %= mod Pn_hash += ord(Pn[i])-ord('A')+1 Pn_hash %= mod# S[0:len..
https://www.acmicpc.net/problem/1417from queue import PriorityQueueN = int(input())P = [0]*Nfor i in range(N): P[i] = int(input()) pq = PriorityQueue() # default : 최솟값을 우선적으로 반환하는 큐for i in range(1,N): # 기호1번 제외 pq.put(-P[i]) # -를 붙임으로써 음수들로 들어가게끔 처리 if N == 1: print(0)else: count = 0 while True: max_value = -pq.get() # 음수중 최소값 반환에 앞에 -를 붙임으로써 절대값 기준 최댓값이 반환되게..
https://www.acmicpc.net/problem/2606N = int(input())M = int(input())adj = [[] for _ in range(N)] # 인접 리스트 [ [], [], ... , []]for _ in range(M): a, b = list(map(int, input().split())) adj[a-1].append(b-1) adj[b-1].append(a-1) check = [0]*Ncheck[0] = 1while True: new = False # if updated for i in range(N): if check[i] == 0: continue # chec..
https://www.acmicpc.net/problem/1068N = int(input())parent = list(map(int, input().split()))R = int(input())# 루트 노드 찾기for i in range(N): if parent[i]==-1: root = i break # 사라지는 노드 판별black = [0]*Nfor i in range(N): u = i while True: if u == R: black[i] = 1 break if u == root: break u = parent[u] # 자식 있는..
문제 7 3 8 8 1 0 2 7 4 44 5 2 6 5위 그림은 크기가 5인 정수 삼각형의 한 모습이다.맨 위층 7부터 시작해서 아래에 있는 수 중 하나를 선택하여 아래층으로 내려올 때, 이제까지 선택된 수의 합이 최대가 되는 경로를 구하는 프로그램을 작성하라. 아래층에 있는 수는 현재 층에서 선택된 수의 대각선 왼쪽 또는 대각선 오른쪽에 있는 것 중에서만 선택할 수 있다.삼각형의 크기는 1 이상 500 이하이다. 삼각형을 이루고 있는 각 수는 모두 정수이며, 범위는 0 이상 9999 이하이다.입력첫째 줄에 삼각형의 크기 n(1 ≤ n ≤ 500)이 주어지고, 둘째 줄부터 n+1번째 줄까지 정수 삼각형이 주어진다. 출력첫째 줄에 합이 최대..
