[문제 링크]
1011번: Fly me to the Alpha Centauri
우현이는 어린 시절, 지구 외의 다른 행성에서도 인류들이 살아갈 수 있는 미래가 오리라 믿었다. 그리고 그가 지구라는 세상에 발을 내려 놓은 지 23년이 지난 지금, 세계 최연소 ASNA 우주 비행
www.acmicpc.net
[배운점]
1. 문제를 잘 읽자. 조건을 일단 잘못 이해했었다.
2. 규칙을 찾기 위해 하나하나 적어보자. => 적고 틀린 곳이 없는지 잘 확인
[기본 로직 OR IDEA]
[구현]
public class Main1011 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int t = 0; t < T; t++){
int x = sc.nextInt();
int y = sc.nextInt();
int dist = y - x;
int max = (int) Math.sqrt(dist);
int count = 0;
if(max == Math.sqrt(dist)){
count = max * 2 - 1;
}else if(max * max < dist && dist <= max * max + max){
count = max * 2;
}else{
count = max * 2 + 1;
}
System.out.println(count);
}
}
}
[참조링크]
[백준] 1011번 : Fly me to the Alpha Centauri - JAVA [자바]
https://www.acmicpc.net/problem/1011 1011번: Fly me to the Alpha Centauri 우현이는 어린 시절, 지구 외의 다른 행성에서도 인류들이 살아갈 수 있는 미래가 오리라 믿었다. 그리고 그가 지구라는 세상에 발을..
st-lab.tistory.com
'Algorithm > BOJ' 카테고리의 다른 글
[BOJ 1058] 친구 (JAVA) (0) | 2021.09.14 |
---|---|
[BOJ 7562] 나이트의 이동 (JAVA) (0) | 2021.09.14 |