ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/2635
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n int
fmt.Fscanln(reader, &n)
var maxCount int
var answer []int
for second := 1; second <= n; second++ {
var numbers = []int{n, second}
for i := 2; numbers[i-2]-numbers[i-1] >= 0; i++ {
numbers = append(numbers, numbers[i-2]-numbers[i-1])
}
if maxCount < len(numbers) {
maxCount = len(numbers)
answer = numbers
}
}
fmt.Fprintln(writer, maxCount)
for i := 0; i < len(answer); i++ {
fmt.Fprintf(writer, "%d ", answer[i])
}
fmt.Fprintln(writer, "")
}
๐จ Python3
# https://www.acmicpc.net/problem/2635
import sys
if __name__ == "__main__":
n = int(sys.stdin.readline())
max_count = 0
answer = []
for second in range(1, n+1):
numbers = [n, second]
i = 2
while numbers[i-2]-numbers[i-1] >= 0:
numbers.append(numbers[i-2]-numbers[i-1])
if max_count < len(numbers):
max_count = len(numbers)
answer = numbers
i += 1
print(max_count)
for i in answer:
print("{} ".format(i), end='')
print()
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 5568๋ฒ / ์นด๋ ๋๊ธฐ [Go][Python3] (0) | 2021.01.30 |
---|---|
BOJ / 2303๋ฒ / ์ซ์ ๊ฒ์ [Go][Python3] (0) | 2021.01.29 |
BOJ / 14916๋ฒ / ๊ฑฐ์ค๋ฆ ๋ [Go][Python3] (0) | 2021.01.27 |
BOJ / 2422๋ฒ / ํ์ค์ ์ด ์ดํ๋ฆฌ์์ ๊ฐ์ ์์ด์คํฌ๋ฆผ์ ์ฌ๋จน๋๋ฐ [Go][Python3] (0) | 2021.01.26 |
BOJ / 1145๋ฒ / ์ ์ด๋ ๋๋ถ๋ถ์ ๋ฐฐ์ [Go][Python3] (0) | 2021.01.25 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ์๊ณ ๋ฆฌ์ฆ
- ๋ฐฑ์ค
- ์๋ฐ
- ํ
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ์๊ฐ๊ต์ฒด
- baekjoon
- dp
- ballet
- ๋ชฝ๊ณ ๋๋น
- Algorithm
- Golang
- ๋งฅ๋ถ
- python3
- BOJ
- go
- ์คํ
- ์ด๋ถํ์
- AWS
- BFS
- ๋งฅ๋ถํ๋ก
- Macbook pro 2012 mid 13
- ๋ฐ๋
- MongoDB
- java
- ๋ถํ ์ ๋ณต
- ๋ธ๋ฃจํธํฌ์ค
- ํ๋ก์ด๋์์ฌ
- ํด์๋งต
- dfs
- Total
- Today
- Yesterday