프로그래밍/Baekjoon
(자바) 백준 알고리즘 2292번 벌집
J_Remind
2019. 4. 11. 17:14
문제
풀이 (Java)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | public class Main{ public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int target = sc.nextInt(); int cnt = 1; int range = 1; int tmp = 1; while(true) { if(range >= target) { break; } tmp = 6*(cnt++); range += tmp; } System.out.println(cnt); } } | cs |
2칸 - 2~7
3칸 - 8~19
4칸 - 20~37
5칸 - 38~61
6 - 12 - 18 - 24 크기로 범위가 커지는 규칙을 찾을 수 있다.