
문제 링크 2004번: 조합 0의 개수 첫째 줄에 정수 $n$, $m$ ($0 \le m \le n \le 2,000,000,000$, $n \ne 0$)이 들어온다. www.acmicpc.net 문제 풀이 def countNum(target, num): cnt = 0 while target > 0: target //= num cnt += target return cnt n, k = map(int, input().split()) count_two = countNum(n, 2) - countNum(k, 2) - countNum(n - k, 2) count_five = countNum(n, 5) - countNum(k, 5) - countNum(n - k, 5) print(min(count_two, coun..

문제 링크 1676번: 팩토리얼 0의 개수 N!에서 뒤에서부터 처음 0이 아닌 숫자가 나올 때까지 0의 개수를 구하는 프로그램을 작성하시오. www.acmicpc.net 문제 풀이 import math n = int(input()) n_factorial = list(map(int, list(str(math.factorial(n))))) cnt = 0 index = len(n_factorial) - 1 while index != 0 : if n_factorial[index] == 0: cnt += 1 index -= 1 else: break; print(cnt) *key point: factorial을 계산해 준 뒤 각 자리수를 리스트에 넣어 반복문으로 해결한다.

문제 링크 9375번: 패션왕 신해빈 첫 번째 테스트 케이스는 headgear에 해당하는 의상이 hat, turban이며 eyewear에 해당하는 의상이 sunglasses이므로 (hat), (turban), (sunglasses), (hat,sunglasses), (turban,sunglasses)로 총 5가지 이다. www.acmicpc.net 문제 풀이 import math t = int(input()) for i in range(t): n = int(input()) type_list = [] type_count = [] for j in range(n): cloth, type = input().split() if type not in type_list: type_list.append(type) ty..

문제 링크 1010번: 다리 놓기 입력의 첫 줄에는 테스트 케이스의 개수 T가 주어진다. 그 다음 줄부터 각각의 테스트케이스에 대해 강의 서쪽과 동쪽에 있는 사이트의 개수 정수 N, M (0 < N ≤ M < 30)이 주어진다. www.acmicpc.net 문제 풀이 import math t = int(input()) for i in range(t): n, m = map(int, input().split()) print(math.factorial(m)//(math.factorial(m-n)*math.factorial(n))) *key point: 조합(Combination)에 대한 이해가 있으면 쉽게 풀 수 있다. 주어진 문제는 M개 중에 N를 고르는 경우의 수 이으로 mCn을 구해준다.

문제 링크 3036번: 링 출력은 총 N-1줄을 해야 한다. 첫 번째 링을 제외한 각각의 링에 대해서, 첫 번째 링을 한 바퀴 돌리면 그 링은 몇 바퀴 도는지 기약 분수 형태 A/B로 출력한다. www.acmicpc.net 문제 풀이 import math n = int(input()) diameter = list(map(int, input().split())) for i in range(1, n): gcd = math.gcd(diameter[0], diameter[i]) print(f'{diameter[0]//gcd}/{diameter[i]//gcd}') *key point: 첫번째 링과 각 링의 반지름의 최소공배수를 구하여 나누어주면 출력해야 할 기약 분수의 분모, 분자를 구할 수 있다.

문제 링크 10815번: 숫자 카드 첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10, www.acmicpc.net 문제 풀이 import sys N = int(sys.stdin.readline()) card_list = list(map(int, sys.stdin.readline().split())) M = int(sys.stdin.readline()) check_list = list(map(int, sys.stdin.readline().split())) card_dict = {} for i in range(len(card_list)):..

문제 링크 1018번: 체스판 다시 칠하기 첫째 줄에 N과 M이 주어진다. N과 M은 8보다 크거나 같고, 50보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에는 보드의 각 행의 상태가 주어진다. B는 검은색이며, W는 흰색이다. www.acmicpc.net 문제 풀이 N, M = map(int, input().split()) start = [] cnt = [] for _ in range(N): start.append(input()) for a in range(N - 7): for b in range(M - 7): index1 = 0 index2 = 0 for i in range(a, a + 8): for j in range(b, b + 8): if (i + j) % 2 == 0: if start[..

문제 링크 2981번: 검문 트럭을 타고 이동하던 상근이는 경찰의 검문을 받게 되었다. 경찰은 상근이가 운반하던 화물을 하나하나 모두 확인할 것이기 때문에, 검문하는데 엄청나게 오랜 시간이 걸린다. 상근이는 시간 www.acmicpc.net 문제 풀이 import math n = int(input()) num, num2 = [], [] for i in range(n): num.append(int(input())) num.sort(reverse=True) for i in range(len(num) - 1): num2.append(num[i] - num[i+1]) greatest_common_divisor = math.gcd(*num2) ans = [greatest_common_divisor] for i i..

문제 링크 11051번: 이항 계수 2 첫째 줄에 \(N\)과 \(K\)가 주어진다. (1 ≤ \(N\) ≤ 1,000, 0 ≤ \(K\) ≤ \(N\)) www.acmicpc.net 문제 풀이 from math import factorial n, k = map(int, input().split()) print(factorial(n) // (factorial(k) * factorial(n - k)) % 10007) *key point: 11050번 문제에서 나머지 계산만 추가해준다.

문제 링크 1934번: 최소공배수 두 자연수 A와 B에 대해서, A의 배수이면서 B의 배수인 자연수를 A와 B의 공배수라고 한다. 이런 공배수 중에서 가장 작은 수를 최소공배수라고 한다. 예를 들어, 6과 15의 공배수는 30, 60, 90등이 있 www.acmicpc.net 문제 풀이 t = int(input()) for _ in range(t): a, b = map(int, input().split()) result = a * b while b > 0: a, b = b, a % b print(result // a) *key point: 두 수의 곱을 유클리드 호제법으로 구한 최대공약수로 나누어 준다.
- Total
- Today
- Yesterday
- 25192
- 백준
- programmer
- til
- 2587
- 13909
- 코육대
- 2738
- 13241
- 24723
- 4134
- 2053
- 26069
- 20920
- 24313
- 25501
- 5597
- Python
- MySQL
- 24060
- SQL
- 2903
- 항해+
- 항해 플러스
- Programmers
- 17103
- Wil
- 벡준
- 1269
- 10807
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |