python-algorithm
백준 15841 Virus Outbreak
무적김두칠
2023. 11. 25. 10:34
https://www.acmicpc.net/problem/15841
15841번: Virus Outbreak
For each input value, the output contains a line in the format: Hour X: Y cow(s) affected, where X is the hour, and Y is the total affected cows that need to be euthanized based on the hour given by X.
www.acmicpc.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
def solution(n):
answer = [0, 1, 1]
for i in range(3, n + 1):
answer.append(answer[-1] + answer[-2])
return answer[n]
if __name__ == '__main__':
while True:
n = int(input())
if n == -1:
break
print(f'Hour {n}: {solution(n)} cow(s) affected')
|
cs |
이 문제는.. 바이러스가 피보나치 수열로 증가하고 있습니다
반응형