본문 바로가기

IT Study/Algorithm

[백준 알고리즘]1011번 Fly me to the Alpha Centauri


규칙에 대한 내용 써야함(좀있다 업데이트)



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
29
30
#include <stdio.h>
 
int main(void)
{
    int test_case;
 
    scanf("%d",&test_case);
    for(int i = 0 ; i <test_case ; i++){
        int x,y;
 
        scanf("%d %d",&x,&y);
 
        int distance  = y-x;
 
        int i = 2;
        while(i*i-(i-1> distance || i*i+< distance){    
            i++;
        }
 
        if(i*< distance){
            printf("%d\n",2*i);
        }else{
            printf("%d\n",2*i-1);
    
        }
    }
 
    
    return 0;
}
cs


'IT Study > Algorithm' 카테고리의 다른 글

[재귀함수]toBinary  (0) 2018.09.07
NN단 (binarySearch 문제)  (0) 2018.08.29
[백준 알고리즘]2292번 벌집  (0) 2018.08.21
[백준 알고리즘]4880번 다음수  (0) 2018.08.21
암호화와 복호화  (0) 2018.05.17