Algorithm
[BOJ] 1011번 : Fly me to the Alpha Centauri
rudgh99_algo
2024. 10. 10. 16:54
1. problem :
https://www.acmicpc.net/problem/1011
2. solution 1 :
#include <bits/stdc++.h>
using namespace std;
long long func(long long a) {
return (2 * sqrt(a) - 1e-9);
}
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
long long x, y;
cin >> t;
while (t--) {
cin >> x >> y;
cout << func(y - x) << '\n';
}
}
source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x12/solutions/1011.cpp
basic-algo-lecture/0x12/solutions/1011.cpp at master · encrypted-def/basic-algo-lecture
바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.
github.com
func함수의 로직이 이해가 가지는 않는다. return (2 * sqrt(a) - 1e-9)를 하는데, 제곱값에서 특이점이 있는 것은 알았으나, 모든 경우의 수에서 적용되는 이유를 모르겠다.