Computer Science/알고리즘 31

알고리즘 | 그래프(Graph)의 정의와 유형, 표현 방법

그래프 Graph 그래프 G는 다음과 같이 정의한다. $ G = (V, E) $ 여기서 V는 Vertices(Node)의 집합이고, E는 Edge의 집합을 의미한다. E의 각 edge는 $(u, v)$의 Pair로, $u, v \in V$이다. 이렇게 edge를 통해 연결된 Vertex u, v를 Adjacent vertices라고 한다. 한 노드(Vertex)의 Degree(차수)는 그 노드가 가진 adjacent vertices로 나타낸다. 그래프의 유형 그래프는 방향성, 무게에 따라 두 유형으로 나뉜다. 1. Directed VS. Undirected Edge의 각 Pair (u, v)에 방향과 순서가 있으면, 이러한 그래프를 Directed Graph라고 한다. 그렇지 않은 경우를 Undirect..

[8.21] pygame_ 토마토 수학게임

나아진 점 : intro를 넣으려 함. 개선할 점 : intro를 만드느라 정작 메인 게임을 못 만듦 ㅋㅋ.. : 화면이 깜빡거림. #-*- coding: utf-8 -*-# ## import import random import sys import math import pygame from pygame import mixer import time from time import sleep from math import pi WINDOW_WIDTH = 800 WINDOW_HEIGHT = 500 ## 한글 폰트 불러오기 pygame.font.init() small_font = pygame.font.SysFont('malgungothic', 10) font = pygame.font.SysFont('malgun..

[8.13] 파이썬 pygame - 토마토 수학교실

#-*- coding: utf-8 -*-# import random import sys import math import pygame from pygame import mixer import time from time import sleep from math import pi WINDOW_WIDTH = 800 WINDOW_HEIGHT = 500 #한글 폰트 불러오기 pygame.font.init() font = pygame.font.SysFont('malgungothic', 20) #아이콘 불러오기 icon = pygame.image.load('tomato.png') pygame.display.set_icon(icon) VELOCITY = 7 MASS = 2 class Car: def __init__(s..

[8.11] 파이썬 pygame - 토마토 수학게임

파이썬 파이게임을 이용해서 만든 간단한 프로그램이다! pygame 모듈을 설치한 후에 첨부파일을 다운받으면 실행시킬 수 있다 :D #-*- coding: utf-8 -*-# import random import sys import math import pygame from pygame import mixer import time from time import sleep WINDOW_WIDTH = 800 WINDOW_HEIGHT = 500 #한글 폰트 불러오기 pygame.font.init() font = pygame.font.SysFont('malgungothic', 20) #토마토 불러오기 redtomato = pygame.image.load('tomatotomato.png') happytomato =..

[8.11] 파이썬 조합 문제

from itertools import combinations def solution(str, k): # k개의 수를 제거해서 만들 수 있는 숫자 찾기 # step 1. 문자열을 리스트로 바꾸기 mylist = list(str) # step 2. 그 중에 k개 빼고 고르기 mylist = list(combinations(mylist, len(mylist)-k)) # step 3. 그 중에 가장 큰 수 찾기 answer = [] for i in mylist: #두 요소를 합치기 answer.append(int(''.join(i))) # step 4. 문자열 형태로 반환하기 answer.sort() answer.reverse() return answer[0] # 그 중에 가장 큰 숫자 찾기 print(sol..