Algorithm

Algorithm/Python

[백준] 11048 이동하기

https://www.acmicpc.net/problem/11048DP로 이전에 이동할 수 있는 좌표 중 가장 큰 값을 가지고 간다 + 현재 칸에 할당된 사탕도 더하기!import sysinput = sys.stdin.readlinen,m = map(int, input().split())maze = []for _ in range(n): maze.append(list(map(int, input().split())))dp = [[0 for _ in range(m)] for _ in range(n)]dp[0][0] = maze[0][0]for y in range(n): for x in range(m): if y>0 and x>0 : dp[y][x] = max(dp[y][x], dp[y-..

Algorithm/Python

[백준] 2448 별 찍기 - 11

https://www.acmicpc.net/problem/2448from collections import dequen = int(input())# 정답 모양을 만드려면 배열의 가로 길이를 2*n-1로 맞춰야 합니다.arr = [[' '] * (2 * n-1) for _ in range(n)] queue = deque()queue.append((0, n - 1, n)) # 시작 위치를 (0, n-1)로 설정while queue: y, x, l = queue.popleft() if l == 3: arr[y][x] = arr[y + 1][x - 1] = arr[y + 1][x + 1] = '*' for i in range(-2, 3): arr[y + ..

Algorithm/Python

[백준] 4344 평균은 넘겠지

https://www.acmicpc.net/problem/4344 c = int(input())for _ in range(c): arr = list(map(int, input().split())) avg = sum(arr[1:])/arr[0] print(f'{round(100*sum(map(lambda x: x>avg, arr[1:]))/arr[0],3)}%')

Algorithm/Python

[백준] 14503 로봇 청소기

https://www.acmicpc.net/problem/14503import sysinput = sys.stdin.readlinen,m = map(int, input().split())r, c, d = map(int, input().split()) # 로봇청소기 초기 위치, 방향mv = [[-1,0],[0,1],[1,0],[0,-1]]board = []for _ in range(n): board.append(list(map(int, input().split())))cnt=0while True: if board[r][c]==0: # 청소 필요 board[r][c]=-1 # 청소 완 cnt+=1 else: isMv=False for _ in..

Algorithm/Python

[백준] 1389 케빈 베이컨의 6단계 법칙

https://www.acmicpc.net/problem/1389import sysfrom collections import dequeinput=sys.stdin.readlinen, m = map(int, input().split())adj = [[n for _ in range(n+1)] for _ in range(n+1)]for i in range(1, n+1): adj[i][i] = 0for _ in range(m): a,b = map(int, input().split()) adj[a][b] = 1 adj[b][a] = 1for k in range(1, n+1): for i in range(1, n+1): for j in range(1, n+1): ..

Algorithm/Python

[백준] 1072 게임

https://www.acmicpc.net/problem/1072import sys, mathinput = sys.stdin.readlinex,y = map(int, input().split())z_start = math.floor(100*y/x)left, right=0, xans=-1if y==x: print(-1)else: while leftz_start: ans=mid right = mid-1 else: left=mid+1 print(ans)

Algorithm/Python

[백준] 1106 호텔

https://www.acmicpc.net/problem/1106 가장 적은 비용을 들여 고객의 수를 주어진 고객의 수 이상으로 확보해야 하기 때문에 0-1 Knapsack Problem의 변형 문제로 보인다! 차이점이라면 가방은 최대 무게 이하여야 한다는 거지만, 여기는 주어진 고객의 수 이상이어야 한다는 것이다. dp 배열의 인덱스는 모은 고객의 수이고, 안의 값에는 해당 고객을 모으기 위해 필요한 최소 비용이다.하나의 도시에서 모을 수 있는 비용 - 고객은 중복이 되기 때문에(배수) 인덱스는 작은 곳부터 c+100까지 구했다.import sysinput = sys.stdin.readlinec,n = map(int, input().split())dp = [0 for _ in range(1101)]f..

Algorithm/Python

[백준] 21317 징검다리 건너기

https://www.acmicpc.net/problem/21317import sysinput = sys.stdin.readlinen = int(input())if n == 1: print(0) sys.exit()arr = []for _ in range(n - 1): arr.append(list(map(int, input().split())))k = int(input())# dp[0][i]: 특수 점프를 사용하지 않고 i에 도달하는 최소 비용# dp[1][i]: 특수 점프를 사용하여 i에 도달하는 최소 비용dp = [[float('inf')] * n for _ in range(2)]dp[0][0] = 0# n=2, n=3 등의 작은 케이스를 명확하게 처리dp[0][1] = arr[0][0..

Algorithm/Python

[백준] 1735 분수

https://www.acmicpc.net/problem/1735 math 라이브러리의 gcd, lcm 함수를 이용해 최대공약수, 최소공배수를 구할 수 있다.gcd : 주어진 숫자들의 최대공약수lcm : 주어진 숫자들의 최소공배수 import matharr = []for _ in range(2): arr.append(list(map(int, input().split())))bunmo = math.lcm(arr[0][1], arr[1][1])bunja = arr[0][0]*(bunmo//arr[0][1])+arr[1][0]*(bunmo//arr[1][1])gcdvalue = math.gcd(bunmo, bunja)print(bunja//gcdvalue, bunmo//gcdvalue)

Algorithm/Python

[백준] 2512 예산

https://www.acmicpc.net/problem/2512n = int(input())budget = list(map(int, input().split()))total = int(input())left, right = 0, max(budget)ans=0while left

yoursin
'Algorithm' 카테고리의 글 목록 (2 Page)