Problem Solving/백준
백준 2292 벌집
tachyonAnB
2020. 10. 2. 20:28
2292번: 벌집
위의 그림과 같이 육각형으로 이루어진 벌집이 있다. 그림에서 보는 바와 같이 중앙의 방 1부터 시작해서 이웃하는 방에 돌아가면서 1씩 증가하는 번호를 주소로 매길 수 있다. 숫자 N이 주어졌��
www.acmicpc.net
이 문제는 관찰과 약간의 산수(?)를 통해 해결할 수 있다. 벌집은 육각형으로 이루어져 있고, 계속 중심의 육각형을 감싸는 방식으로 확장하므로, 바깥쪽 둘레는 항상 안쪽보다 6씩 더 길어진다. 그 점에 착안하여 공식을 세우면 된다
<코드>
#include <iostream>
#define endl '\n'
using namespace std;
int cnt,n,m=1;
int main()
{
ios::sync_with_stdio(false);cin.tie(NULL);
cin>>n;
while(n>m){
cnt++;
m+=6*cnt;
}
cout<<cnt+1<<endl;
return 0;
}
def main():
n = int(input())
if n == 1:
return n
else:
i = 1
while int((6*i+6)*i/2)+1 <= n-1:
i += 1
return i+1
print(main())