본문 바로가기
반응형

알고리즘149

(Python/🥉2)최댓값 문제 출처:https://www.acmicpc.net/problem/2566 문제 풀이: lst = [] for i in range(9): lst.append(list(map(int,input().split()))) max = lst[0][0] x = 1 y = 1 for i in range(9): for j in range(9): if lst[i][j] > max: max = lst[i][j] x = i+1 y = j+1 print(max) print(x,y) 2022. 11. 11.
(Python/🥉5)행렬의 덧셈 문제 출처:https://www.acmicpc.net/problem/2738 2738번: 행렬 덧셈 첫째 줄에 행렬의 크기 N 과 M이 주어진다. 둘째 줄부터 N개의 줄에 행렬 A의 원소 M개가 차례대로 주어진다. 이어서 N개의 줄에 행렬 B의 원소 M개가 차례대로 주어진다. N과 M은 100보다 작거나 같 www.acmicpc.net 문제 풀이: N,M = map(int,(input().split(' '))) list_2 = [] for i in range(N): list_2.append(list(map(int,input().split(' ')))) for i in range(N): plus = list(map(int,input().split(' '))) for j in range(M): list_2[.. 2022. 11. 9.
(Python/🥈2)9141번: 신나는 함수 실행 문제 출처:https://www.acmicpc.net/problem/9184 9184번: 신나는 함수 실행 입력은 세 정수 a, b, c로 이루어져 있으며, 한 줄에 하나씩 주어진다. 입력의 마지막은 -1 -1 -1로 나타내며, 세 정수가 모두 -1인 경우는 입력의 마지막을 제외하면 없다. www.acmicpc.net 풀이: dp = [[[0]*(21) for _ in range(21)] for _ in range(21)] def w(a, b, c): if a 20: return w(20, 20, 20) if dp[a][b][c]: return dp[a][b][c] if a < b < c: dp[a][b][c] = w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c) retur.. 2022. 11. 7.
(Python/🥉1)24416번: 알고리즘 수업 - 피보나치 수 1 문제 출처:https://www.acmicpc.net/problem/24416 24416번: 알고리즘 수업 - 피보나치 수 1 오늘도 서준이는 동적 프로그래밍 수업 조교를 하고 있다. 아빠가 수업한 내용을 학생들이 잘 이해했는지 문제를 통해서 확인해보자. 오늘은 n의 피보나치 수를 재귀호출과 동적 프로그래밍 www.acmicpc.net 문제 풀이: N = int(input()) dp = [0]*(N+1) dp[1] = 1 for i in range(2, N+1): dp[i] = dp[i-1] + dp[i-2] print(dp[-1], N-2) 2022. 11. 7.
(Python/🥉2) 25501번: 재귀의 귀재 문제 출처:https://www.acmicpc.net/problem/25501 문제 풀이: import sys sys.stdin = open('/Users/song/Desktop/Python/Python/h.txt', 'r') n = int(input()) def recursion(s, l, r): if l >= r: return 1,l elif s[l] != s[r]: return 0,l else: return recursion(s, l+1, r-1) def isPalindrome(s): return recursion(s, 0, len(s)-1) for i in range(n): isp, recu =isPalindrome(input().strip("\n")) print(isp, recu+1) # 0부터.. 2022. 11. 5.
(Python/🥉2)대표값2 문제 출처:https://www.acmicpc.net/problem/2587 2587번: 대표값2 어떤 수들이 있을 때, 그 수들을 대표하는 값으로 가장 흔하게 쓰이는 것은 평균이다. 평균은 주어진 모든 수의 합을 수의 개수로 나눈 것이다. 예를 들어 10, 40, 30, 60, 30의 평균은 (10 + 40 + 30 + 60 + www.acmicpc.net 풀이: res = sorted([int(input()) for _ in range(5)]) print(sum(res)// len(res), res[2]) 2022. 11. 5.
반응형