일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
Tags
- conjugate pseudo label paper
- Meta Pseudo Labels
- remixmatch paper
- 백준 알고리즘
- CycleGAN
- shrinkmatch
- WGAN
- CoMatch
- shrinkmatch paper
- adamatch paper
- BYOL
- cifar100-c
- 컴퓨터구조
- Pix2Pix
- semi supervised learnin 가정
- dcgan
- ConMatch
- mme paper
- tent paper
- mocov3
- simclrv2
- SSL
- Pseudo Label
- CGAN
- Entropy Minimization
- dann paper
- UnderstandingDeepLearning
- GAN
- 딥러닝손실함수
- 최린컴퓨터구조
Archives
- Today
- Total
Hello Data
백준 알고리즘 1735번 [분수합] 파이썬 본문
https://www.acmicpc.net/problem/1735
1735번: 분수 합
첫째 줄과 둘째 줄에, 각 분수의 분자와 분모를 뜻하는 두 개의 자연수가 순서대로 주어진다. 입력되는 네 자연수는 모두 30,000 이하이다.
www.acmicpc.net
접근하기는 쉬웠는데 깔끔한 코드로 접근하기는 어려웠다. 일단 유클리드 호제법을 이용해서 최대공약수를 구해주고, 분모와 분자를 따로따로 구한 후, 분모와 분자에 대한 최대공약수로 나누어주면 되는 문제였다. 처음에 다른 분들의 코드를 보면서 이해가 안간 부분은 분자 부분이었는데 이는 예시로 한번 접근해보면 쉬운 거 같다.
a, b = map(int, input().split())
c, d = map(int, input().split())
def gcd(x, y): # x < y
while x % y != 0:
mod = x % y
x = y
y = mod
return y
g1 = gcd(b, d)
demon = b * d // g1
mole = a * (d // g1) + c * (b // g1)
g2 = gcd(demon, mole)
print(mole // g2, demon // g2)
'백준알고리즘' 카테고리의 다른 글
백준 알고리즘 13909번 [창문닫기] 파이썬 (0) | 2023.04.29 |
---|---|
백준 알고리즘 7785번 [회사에 있는 사람] 파이썬 (0) | 2023.04.23 |
백준 알고리즘 1181번 [단어 정렬] 파이썬 (0) | 2023.04.23 |
백준 알고리즘 2231번 [분해합] 파이썬 (0) | 2023.04.20 |