Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

Joon's Space

[Python] 백준 알고리즘 #2292 벌집 본문

Algorithm/baekjoon

[Python] 백준 알고리즘 #2292 벌집

Happy Joon 2021. 1. 13. 02:32

문제풀이

 

안쪽부터, 갯수를 세어보았을 때,

첫번째 층 1, 두번째 층 2~7, 세번째 층 8~19, 네번째 층 20~37 다섯번째 층 38~61

 

a(시작점) b(끝점) a증가율 b증가율
2 7    
8 19 6 12
20 37 12 18
38 61 18 24

다음을 보면 증가율이 6배수로 증가하는 것을 볼 수 있다.

 

소스코드

import sys
input = sys.stdin.readline
a=2
b=7
count=1
n = int(input())

if n==1:
    print(1)
else:
    while True:
        if a<=n and b>=n:
            break
        a+=6*count
        b+=6*(count+1)
        count+=1
    print(count+1)

 

 

www.acmicpc.net/problem/2292

 

2292번: 벌집

위의 그림과 같이 육각형으로 이루어진 벌집이 있다. 그림에서 보는 바와 같이 중앙의 방 1부터 시작해서 이웃하는 방에 돌아가면서 1씩 증가하는 번호를 주소로 매길 수 있다. 숫자 N이 주어졌

www.acmicpc.net

 

반응형