문제
이 나라의 규칙에 맞는 날짜계산 방식으로 year를 구해라
year이랑 e, s, m 간의 관계에 대한 식을 쉽게 표현할 수록 풀이가 쉬워진다.
2 try - success
import sys
sys.stdin = open('../DFS/in.txt', 'rt')
# input = sys.stdin.readline
e,s,m = map(int, input().split())
def DFS(year):
global e
res = year
res2 = year
res3 = year
while res > 15:
res -= 15
if res != e:
return False
while res2 > 28:
res2 -= 28
if res2 != s:
return False
while res3 > 19:
res3 -= 19
if res3 != m:
return False
return year
y = 0
while True:
if DFS(y) != False:
print(y)
break
y += 1
3 try - success
import sys
sys.setrecursionlimit(10**6)
sys.stdin = open('../DFS/in.txt', 'rt')
# input = sys.stdin.readline
e,s,m = map(int, input().split())
def DFS(year):
global e
global s
global m
if (year-e) % 15 == 0 and (year-s) % 28 == 0 and (year-m) % 19 == 0:
return True
return False
y = 0
while True:
if DFS(y) == True:
print(y)
break
y+=1
'⚡️algorithm' 카테고리의 다른 글
[그래프] 백준 1991. 트리 순회 (전위 순회, 중위 순회, 후위 순회) (0) | 2022.04.29 |
---|---|
[완전탐색, 파이썬] 백준 1107. 리모컨 (0) | 2022.04.29 |
[BFS 파이썬] 백준 7576. 토마토 (0) | 2022.04.29 |
[DFS, 파이썬] 백준 4963. 섬의 개수 (0) | 2022.04.29 |
[DFS] 백준 10265. MT - 틀림 (0) | 2022.04.28 |