Python 108

[python/1003]피보나치 함수

https://www.acmicpc.net/problem/1003 1003번: 피보나치 함수 각 테스트 케이스마다 0이 출력되는 횟수와 1이 출력되는 횟수를 공백으로 구분해서 출력한다. www.acmicpc.net 더보기 내 코드 cnt0 = 0 cnt1 = 0 # 문제에서 나온 함수 def fibonacci(N): global cnt0, cnt1 if N == 0: cnt0 += 1 return 0 elif N == 1: cnt1 += 1 return 1 else: return fibonacci(N-1) + fibonacci(N-2) if __name__=='__main__': # T 입력 받기 T = int(input()) # N의 범위가 40 이하 # N이 0일 때 (0의 개수, 1의개수) == [..

알고리즘/백준 2020.04.07

[python]Is my friend cheating?

https://www.codewars.com/kata/5547cc7dcad755e480000004/train/python Codewars: Train your coding skills Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential. www.codewars.com 더보기 내 코드 # My Code def removNb(n): answer = [] sum = int((n+1)*n/2) # a를 1부터 n 만큼 증가시키면서 b를 찾는다. for a in range(1, n+1): # b를 수식으로 정리하면 아래와 같다. # b =..

[python]What's a Perfect Power anyway?

https://www.codewars.com/kata/54d4c8b08776e4ad92000835/train/python Codewars: Train your coding skills Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential. www.codewars.com 더보기 내 코드 # My Code import math # 에라토스테네스 체 응용 def isPP(n): # 효율적으로 코딩하기 위해서는 n의 제곱근까지만 확인 for m in range(2, int(math.sqrt(n)) + 1): # 지수함수의 역연산이 필요하므..

[python/2748]피보나치 수2

https://www.acmicpc.net/problem/2748 2748번: 피보나치 수 2 문제 피보나치 수는 0과 1로 시작한다. 0번째 피보나치 수는 0이고, 1번째 피보나치 수는 1이다. 그 다음 2번째 부터는 바로 앞 두 피보나치 수의 합이 된다. 이를 식으로 써보면 Fn = Fn-1 + Fn-2 (n>=2)가 된다. n=17일때 까지 피보나치 수를 써보면 다음과 같다. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597 n이 주어졌을 때, n번째 피보나치 수를 www.acmicpc.net 더보기 내 코드 import sys # 재귀형식으로 풀 경우 # 반복 작업을 하기 때문에 느림 def fibo(n): return ..

알고리즘/백준 2020.04.02

[python]Beginner Series#1 School Paperwork

https://www.codewars.com/kata/55f9b48403f6b87a7c0000bd/train/python Codewars: Train your coding skills Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential. www.codewars.com 더보기 내 코드 n과 m이 0보다 작을 경우는 0을 return 한다. 그 이외의 경우는 n과 m의 곱한 값을 return 한다. # My Code def paperwork(n, m): return (0 if n

[python/14889]스타트와 링크

https://www.acmicpc.net/problem/14889 14889번: 스타트와 링크 예제 2의 경우에 (1, 3, 6), (2, 4, 5)로 팀을 나누면 되고, 예제 3의 경우에는 (1, 2, 4, 5), (3, 6, 7, 8)로 팀을 나누면 된다. www.acmicpc.net 더보기 내 코드 from itertools import combinations def solv(N, S, team): # 가장 작은 값 저장 및 비교 변수 min_tmp = 99999 for i in range(len(team) // 2): # start 팀 team_start = team[i] start_sum = 0 # link 팀 team_link = team[-i - 1] link_sum = 0 for j in..

알고리즘/백준 2020.03.31

[python/14888]연산자 끼워넣기

https://www.acmicpc.net/problem/14888 14888번: 연산자 끼워넣기 첫째 줄에 수의 개수 N(2 ≤ N ≤ 11)가 주어진다. 둘째 줄에는 A1, A2, ..., AN이 주어진다. (1 ≤ Ai ≤ 100) 셋째 줄에는 합이 N-1인 4개의 정수가 주어지는데, 차례대로 덧셈(+)의 개수, 뺄셈(-)의 개수, 곱셈(×)의 개수, 나눗셈(÷)의 개수이다. www.acmicpc.net 더보기 내 코드 import sys def Insert_Operator(now, level): if level == N: global min_n, max_n max_n = max(now, max_n) min_n = min(now, min_n) return # 더하기 if oper[0] > 0: op..

알고리즘/백준 2020.03.28

[python]Find the Difference in Age between Oldest and Youngest Family Members

https://www.codewars.com/kata/5720a1cb65a504fdff0003e2/train/python Codewars: Train your coding skills Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential. www.codewars.com (가장 나이가 적은 수, 가장 나이가 많은 수, 둘의 차이)를 출력하는 문제이다. 더보기 내 코드 # My Code def difference_in_ages(ages): youngest_age = min(ages) oldest_age = max(ages) return..

728x90