목록전체 글 (163)
Bamboo is coming
📖 요즘 수학 공부를 하고 있어서 그런지 금방 규칙이 보였다. 이래서 프로그래머들은 수학 공부를 해야되나보다.. import sys input = sys.stdin.readline n, m =map(int,input().split()) print(n*m-1)
📍 백준 코드플러스 >> 코딩 테스트 준비 - 기초(브루트 포스) 📖 #백준 2309 일곱 난쟁이 브론즈2 (브루트 포스) n = 9 heights = [int(input()) for _ in range(n)] tmp1, tmp2 = 0, 0 for i in range(n): for j in range(i+1, n): if sum(heights) -(heights[i]+heights[j]) == 100: tmp1 = heights[i] tmp2 = heights[j] break if(tmp1 > 0 and tmp2 > 0): break heights.remove(tmp1) heights.remove(tmp2) print('\n'.join(map(str, sorted(heights))))
📍 백준 코드플러스 >> 코딩 테스트 준비 - 기초(수학) 📖 #백준 10430 나머지 브론즈 5 (수학) import sys input = sys.stdin.readline A,B,C = map(int,input().split()) print((A+B)%C) print(((A%C) + (B%C))%C) print((A*B)%C) print(((A%C) * (B%C))%C)
- 알고리즘 분류 : 수학, 구현 💜 올해 첫 알고리즘 문제는 재귀 구현 알고리즘이다. 나의 숙원 사업이자 쥐어뜯어도 헷갈리는 재귀... 기필코.... 재귀를 자유자재로 #백준 팩토리얼 브론즈3 재귀 import sys input = sys.stdin.readline N = int(input()) result = 1 def Factorial(n): global result if(n > 1): return n * Factorial(n-1) else: return 1 print(Factorial(N)) 파이썬은 최대 재귀 가능 횟수가 천 번이다. 하지만 sys를 사용해서 횟수 제한을 해제하는 함수도 따로 있다.
- 알고리즘 분류 : 그래프 이론, 그래프 탐색, 너비 우선 탐색, 깊이 우선 탐색 # 백준 1325 효율적인 해킹 실버2 import sys import collections input = sys.stdin.readline def bfs(start): cnt = 1 visited = [0 for _ in range(N+1)] visited[start] = 1 queue = collections.deque([start]) while queue: u=queue.popleft() for v in com[u]: if not visited[v]: queue.append(v) visited[v]=1 cnt += 1 return cnt N, M = map(int,input().split()) # 컴퓨터 N, 관계 ..
- 알고리즘 분류 : 구현, 문자열 #백준 16113 시그널 실버2 문자열 import sys input= sys.stdin.readline #시그널의 총 길이는 항상 5의 배수(=행이 5개) #숫자와 숫자 사이에는 1열 이상의 공백 존재(첫번째와 마지막 숫자 앞뒤에는 공백 X) #숫자는 3열을 차지, 숫자 1은 다른 숫자와 다르게 1열 차지 #열로 배열을 만들어서 열이 공백인 부분 제외 N = int(input()) #시그널의 길이 AllOfSignal = input() col = N//5 #시그널의 column, row는 언제나 5 signal = [[0 for _ in range(5)]for _ in range(col)] #열을 기준으로 시그널 배열 생성(공백으로 숫자 구분) tmp = 0 ans ..
알고리즘 분류 : 자료구조, 스택 #백준 2841 외계인의 기타 연주 실버1 스택 import sys input = sys.stdin.readline #만약, 어떤 줄의 프렛을 여러 개 누르고 있다면, 가장 높은 프렛의 음이 발생한다. N,P = map(int,input().split()) #멜로디의 음 N, 한 줄의 프렛 P cnt = 0 #움직임 melody = [] line,fret=map(int,input().split()) #새로운 멜로디 음 line, 새로 누를 프렛 fret melody.append(fret) cnt += 1 for i in range(N-1): n,p=map(int,input().split()) #다음 멜로디 음 n, 다음 누를 프렛 p if(n==line): #음이 같으면..
- 알고리즘 분류 : 자료구조, 스택 #백준 1935 후위표기식2 실버3 스택 import sys input = sys.stdin.readline stack = [] N=int(input()) #피연산자 개수 N txt = input() #후위표기식 opr = [] for i in range(N): opr.append(input().strip()) for i in txt.strip(): if(i>="A" and i
class Solution { public int solution(int[][] sizes) { int answer = 0; int max_h, max_w; int tmp; for(int i=0;i
- 알고리즘 분류 : 그래프이론, 그래프탐색, 너비우선탐색, 깊이우선탐색 #백준 13565 침투 from collections import deque import sys input = sys.stdin.readline def bfs(y,x): q = deque() q.append((y,x)) graph[y][x]=2 while q: y,x=q.popleft() graph[y][x]=2 for dy,dx in d: Y,X = y+dy, x+dx if (0