알고리즘/백준
백준_2292 - JAVA
맏리믓
2022. 12. 22. 11:29
- 알고리즘
거쳐야 하는 방의 개수는 다음과 같다.
N | 지나는 방의수 |
1 | 1 |
2~7 | 2 |
8~19 | 3 |
20~37 | 4 |
방이 6각형이기 때문에 지나는 방의 수가 변하는 방 번호의 시작점은 (2->8) 6증가, (8 -> 20) 12증가처럼 6의 배수 만큼씩 증가 한다.
- 풀이
import java.io.*;
public class B_2292 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s1 = br.readLine();
int N = Integer.parseInt(s1);
int n = 1;
int start = 2;
if(N == 1){
System.out.println("1");
} else {
while(start <= N){
start += 6*n;
n += 1;
}
System.out.println(n);
}
}
}