Algorithm
백준 2292번: 벌집
qlyh8
2018. 10. 24. 04:12
문제 출처: https://www.acmicpc.net/problem/2292
규칙찾기.
1) 1
2) 2-7
3) 8-19: 7+1 ~ 7+6*2
4) 20-37: 19+1 ~ 19+6*3
5) 38-61: 38+1 ~ 37+6*4
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 | import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(reader.readLine()); if(N == 1){ System.out.println("1"); return; } int start = 2, end = 7, depth = 1; while(true){ if(start <= N && N <= end){ System.out.println(depth+1); break; } else { ++depth; start = end+1; end += 6*depth; } } } } | cs |