본문 바로가기
알고리즘/백준 BOJ

[ BOJ/C# ] 2292 벌집

by 왹져박사 2023. 10. 17.
728x90

https://www.acmicpc.net/problem/2292

 

2292번: 벌집

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

www.acmicpc.net

전에 CT에서 많이 본 유형의 문제이다. 

각 원형의 겹을 하나로 생각하면 된다. 

using System;
using System.IO;

namespace B2292
{
    class Program
    {
        static void Main()
        {
            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());

            int n = int.Parse(sr.ReadLine());

            int count = 1;
            long range = 1;
            long temp = 1;

            while (true)
            {
                if (range >= n) break;
                temp = 6 * count;
                count++;
                range += temp;
            }
            sw.Write(count);
            sr.Close();
            sw.Flush();
            sw.Close();
        }
    }
}

728x90