ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/1789
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var s int
fmt.Fscanln(reader, &s)
var start, end int = 1, s
var mid int
var answer int
for start <= end {
mid = (start + end) / 2
if mid*(mid+1)/2 <= s {
answer = mid
start = mid + 1
} else {
end = mid - 1
}
}
fmt.Fprintln(writer, answer)
}
๐จ Python3
# https://www.acmicpc.net/problem/1789
import sys
if __name__ == "__main__":
s = int(sys.stdin.readline())
start, end = 1, s
mid, answer = 0, 0
while start <= end:
mid = (start + end) // 2
if mid*(mid + 1) // 2 <= s:
answer = mid
start = mid + 1
else:
end = mid - 1
print(answer)
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 16165๋ฒ / ๊ฑธ๊ทธ๋ฃน ๋ง์คํฐ ์ค์์ด [Go][Python3] (0) | 2021.02.28 |
---|---|
BOJ / 11478๋ฒ / ์๋ก ๋ค๋ฅธ ๋ถ๋ถ ๋ฌธ์์ด์ ๊ฐ์ [Go][Python3] (0) | 2021.02.27 |
BOJ / 10994๋ฒ / ๋ณ ์ฐ๊ธฐ 19 [Go][Python3] (0) | 2021.02.25 |
BOJ / 20301๋ฒ / ๋ฐ์ ์์ธํธ์ค [Go][Python3] (0) | 2021.02.24 |
BOJ / 12789๋ฒ / ๋ํค๋ํค ๊ฐ์๋๋ฆฌ๋ฏธ [Go][Python3] (0) | 2021.02.23 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- go
- BFS
- ์๋ฐ
- dfs
- ํ๋ก์ด๋์์ฌ
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- python3
- ํด์๋งต
- ๋งฅ๋ถํ๋ก
- Golang
- ๋ชฝ๊ณ ๋๋น
- ์ด๋ถํ์
- Macbook pro 2012 mid 13
- MongoDB
- ๋ถํ ์ ๋ณต
- AWS
- ์๊ณ ๋ฆฌ์ฆ
- java
- dp
- ํ
- ballet
- ๋ธ๋ฃจํธํฌ์ค
- ๋ฐฑ์ค
- Algorithm
- ๋ฐ๋
- ์คํ
- baekjoon
- ์๊ฐ๊ต์ฒด
- ๋งฅ๋ถ
- BOJ
- Total
- Today
- Yesterday