Skip to content

Instantly share code, notes, and snippets.

@jc3wrld999
jc3wrld999 / binary_search.py
Last active March 20, 2023 09:56
alogoriothms-python
def binary_search(arr, x):
if len(arr) == 0:
return False
elif len(arr) == 1:
return True if arr[0] == x else False
mid = len(arr)//2
if arr[mid] == x:
return True
elif arr[mid] > x:
def bfs(graph, root):
visited = []
queue = [root]
while queue:
node = queue.pop(0)
if node not in visited:
visited.append(node)
queue.extand(graph[node])
return visited
def fill_tiles(N):
a=b=1
for _ in range(N):
a,b=b,a+b
return a
print(fill_tiles(12))
def alarm():
'''
백준 2884
'''
H , M = map(int, input().split())
total = H * 60 + M - 45
if total < 0:
total += 60 *24
H = total // 60
M = total % 60
import heapq
def find_mid(arr):
'''
leetcode 295
'''
mid = []
small = [] # 최대힙
large = [] # 최소힙
import itertools
def get_prime_number(numbers):
'''
프로그래머스 42839 소수 찾기(완전 탐색)
'''
answer = 0
l = [n for n in numbers]
# 만들 수 있는 수 순열 만들기
'''
https://wikidocs.net/105425
'''
import bisect
result = []
for score in [33, 99, 77, 70, 89, 90, 100]:
pos = bisect.bisect([60, 70, 80, 90], score) # 점수를 삽입할 위치 반환
grade = 'FDCBA'[pos]
result.append(grade)
animals = ['dog', 'cat', 'rabbit', 'tiger']
dic = {}
for animal in animals:
if animal in dic.keys():
dic[animal] += 1
else:
dic[animal] = 1
print(dic)
'''
기본적인 딕셔너리 사용법
@jc3wrld999
jc3wrld999 / N_M.py
Last active April 4, 2023 08:51
backtracking
'''
백준 15649. 1 ~ N으로 M개짜리 조합 만들기
'''
n,m = list(map(int,input().split()))
s = []
def dfs():
if len(s)==m:
print(' '.join(map(str,s)))
'''
백준 1260. bfs, dfs
'''
from collections import defaultdict
# 양방향 그래프 만들기
n, m, v = map(int, input().split())
graph = defaultdict(list)
for i in range(m):
n1, n2 = map(int, input().split())
graph[n1].append(n2)