[BOJ] 1011번 : Fly me to the Alpha Centauri
2024. 10. 10. 16:54ㆍAlgorithm
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)를 하는데, 제곱값에서 특이점이 있는 것은 알았으나, 모든 경우의 수에서 적용되는 이유를 모르겠다.
'Algorithm' 카테고리의 다른 글
[BOJ] 1920번 : 수 찾기 (1) | 2024.10.31 |
---|---|
[BOJ] 1038번 : 감소하는 수 (2) | 2024.10.11 |
[BOJ] 2482번 : 색상환 (0) | 2024.10.08 |
[BOJ] 11660번 : 구간 합 구하기 5 (0) | 2024.10.07 |
[BOJ] 9657번 : 돌 게임 3 (1) | 2024.10.06 |