ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/13301
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)
if n == 1 {
fmt.Fprintln(writer, 4)
return
} else if n == 2 {
fmt.Fprintln(writer, 6)
return
}
var sides = make([]int, n)
sides = computeSides(sides)
fmt.Fprintln(writer, getPerimeter(sides))
}
func computeSides(sides []int) []int {
sides[0] = 1
sides[1] = 1
for i := 2; i < len(sides); i++ {
sides[i] = sides[i-1] + sides[i-2]
}
return sides
}
func getPerimeter(sides []int) (perimeter int) {
a := sides[len(sides)-1]
b := sides[len(sides)-2]
perimeter = a*4 + b*2
return
}
๐จ Python3
# https://www.acmicpc.net/problem/13301
import sys
def compute_sides(sides):
sides[0] = 1
sides[1] = 1
for i in range(2, len(sides)):
sides[i] = sides[i-1] + sides[i-2]
return sides
def get_perimeter(sides):
a = sides[len(sides)-1]
b = sides[len(sides)-2]
perimeter = a*4 + b*2
return perimeter
if __name__ == "__main__":
n = int(sys.stdin.readline())
if n == 1:
print(4)
sys.exit()
elif n == 2:
print(6)
sys.exit()
sides = [0 for i in range(n)]
sides = compute_sides(sides)
print(get_perimeter(sides))
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 19947๋ฒ / ํฌ์์ ๊ท์ฌ ๋ฐฐ์ฃผํ [Go][Python3] (0) | 2021.01.20 |
---|---|
BOJ / 9655๋ฒ / ๋ ๊ฒ์ [Go][Python3] (0) | 2021.01.19 |
BOJ / 9625๋ฒ / BABBA [Go][Python3] (0) | 2021.01.17 |
BOJ / 14697๋ฒ / ๋ฐฉ ๋ฐฐ์ ํ๊ธฐ [Go][Python3] (0) | 2021.01.16 |
BOJ / 2309๋ฒ / ์ผ๊ณฑ ๋์์ด [Go][Python3] (0) | 2021.01.15 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ๋ชฝ๊ณ ๋๋น
- ์ด๋ถํ์
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ๋ฐฑ์ค
- ์๊ฐ๊ต์ฒด
- Macbook pro 2012 mid 13
- ์คํ
- ํ๋ก์ด๋์์ฌ
- dfs
- ์๊ณ ๋ฆฌ์ฆ
- baekjoon
- ballet
- MongoDB
- dp
- BOJ
- ์๋ฐ
- ํ
- go
- ๋ถํ ์ ๋ณต
- ๋ธ๋ฃจํธํฌ์ค
- java
- AWS
- ๋งฅ๋ถํ๋ก
- ๋งฅ๋ถ
- python3
- Golang
- ๋ฐ๋
- BFS
- Algorithm
- ํด์๋งต
- Total
- Today
- Yesterday