백준 5554 - 심부름 가는 길 python
·
Algorithm/백준
파이썬에서 / 와 // 의 차이에 유의해서 풀자. //는 /와 달리 정수형의 결과값을 반환한다. import sys input = sys.stdin.readline home_to_school = int(input()) school_to_pc = int(input()) pc_to_academy = int(input()) academy_to_home = int(input()) sum = home_to_school + school_to_pc + pc_to_academy + academy_to_home print(sum // 60) print(sum % 60) www.acmicpc.net/problem/5554 5554번: 심부름 가는 길 승균이는 매일 학교, PC방, 학원에 다닌다. 반복되는 일상에 익숙해진 ..
백준 5339 - 콜센터
·
Algorithm/백준
파이썬 multiline string 출력은 ''' ''' 나 """ """을 이용하면 되고, 백슬래시를 출력하기 위해서는 앞에 \를 하나 더 붙여주어야 한다. print(""" /~\\ ( oo| _\\=/_ / _ \\ //|/.\\|\\\\ || \\ / || ============ | | | | | | """) www.acmicpc.net/problem/5339 5339번: 콜센터 스타워즈에 등장하는 로봇인 C3PO는 요즘 콜센터에 근무하고 있다. 콜센터에 앉아있는 C3PO를 그리는 프로그램을 작성하시오. www.acmicpc.net
백준 3046 - 파이썬 R2 (구현)
·
Algorithm/백준
import sys input = sys.stdin.readline #입력값 R1과 평균 S # S = (R1 + R2) / 2 # S = R1/2 + R2/2 # 2S - R1 = R2 #출력값 R2 R1, S = map(int, input().split()) print(2*S - R1); www.acmicpc.net/problem/3046
백준 3003 - 파이썬 기초 구현문제(킹, 퀸, 룩, 비숍, 나이트, 폰)
·
Algorithm/백준
import sys input = sys.stdin.readline lists = list(map(int, input().split())) normal = [1, 1, 2, 2, 2, 8] answer = [] for i in range(len(lists)): answer.append(normal[i] - lists[i]) print(*answer)
백준 2845 - python 풀이
·
Algorithm/백준
구현부터 차근차근 연습 import sys input = sys.stdin.readline # L은 사람의 수 # P는 파티장 넓이 L, P = map(int, input().split()) attend = list(map(int, input().split())) real = L * P for i in attend: print(i - real, end=' ')
백준 1550- 16진수 python (구현)
·
Algorithm/백준
파이썬 내장함수를 이용하면 해당 진수로 쉽게 변환이 가능하다. import sys input = sys.stdin.readline #파이썬 내장함수 print(int(input(),16)) www.acmicpc.net/problem/1550 1550번: 16진수 첫째 줄에 16진수 수가 주어진다. 이 수의 최대 길이는 6글자이다. 16진수 수는 0~9와 A~F로 이루어져 있고, A~F는 10~15를 뜻한다. 또, 이 수는 음이 아닌 정수이다. www.acmicpc.net
백준 7562 - python bfs로 푼 풀이
·
Algorithm/백준
BFS 정복하려고 BFS문제만 엄청 푸는 중.. from collections import deque import sys input = sys.stdin.readline dx = [1, 2, 2, 1, -1, -2, -2, -1] dy = [-2, -1, 1, 2, -2, -1, 1, 2] def bfs(x, y, end_x, end_y): q = deque() #초기 위치를 큐에 넣어준다 q.append([x, y]) M[x][y] = 1 while q: x, y = q.popleft() if x == end_x and y == end_y: # 13행에 값을 더해주기 위해 추가했던 초기값 1을 빼준다. return M[x][y] - 1 for i in range(8): nx = x + dx[i] ny ..
백준 11725- 트리의 부모 찾기
·
Algorithm/백준
bfs로 풀어주었다. from collections import deque import sys input = sys.stdin.readline N = int(input()) G = [[] for i in range(N+1)] for _ in range(N-1): a, b = map(int, input().split()) G[a].append(b) G[b].append(a) q=deque() q.append(1) ancestor = {} checked = [0] * (N+1) while q: parent = q.popleft() for i in G[parent]: if not checked[i]: ancestor[i] = parent q.append(i) checked[i] = 1 for i in rang..
백준 11724 연결 요소의 개수- 파이썬 풀이
·
Algorithm/백준
from collections import deque import sys input = sys.stdin.readline N, M = map(int,input().split()) G = [[] for _ in range(N+1)] visited = [0] * (N+1) for _ in range(M): u, v = map(int, input().split()) G[u].append(v) G[v].append(u) q = deque() connect = 0 for i in range(1,N+1): #만약 방문하지 않았으면 if visited[i] == 0: #방문 처리 해주고 visited[i] = 1 #큐에 추가 q.append(i) #연결되는 갯수 늘어났으므로 하나 추가 connect += 1 #큐가 ..
takoyummy
'Algorithm/백준' 카테고리의 글 목록 (3 Page)