본문 바로가기

Programming/BaekJoon

[C++] 백준 1011번 : Fly me to the Alpha Centauri


https://www.acmicpc.net/problem/1011




#include <iostream>

using namespace std;

int main() {

int n;

scanf("%d",&n);

long long *T_case = new long long[n];

long long a, b;

for (int i = 0; i < n; i++) {

scanf("%d %d", &a, &b);

T_case[i] = b - a;

}

long long cnt = 0;

long long max_dis = 0;


for (int i = 0; i < n; i++) {

while (max_dis < T_case[i]) {

cnt++;

if (cnt % 2 == 1) 

max_dis = (cnt-1) * (cnt + 1) / 4 + (cnt + 1) / 2;

else

max_dis = cnt*(cnt + 2) / 4;

}

printf("%d\n", cnt);

max_dis = 0;

cnt = 0;

}

}