설명없음
백준 1484: 다이어트 [C/C++]
치킨먹고싶어요
2022. 6. 8. 15:26
https://www.acmicpc.net/problem/1484
1484번: 다이어트
성원이는 다이어트를 시도중이다. 성원이는 정말 정말 무겁기 때문에, 저울이 부셔졌다. 성원이의 힘겨운 다이어트 시도를 보고만 있던 엔토피아는 성원이에게 새로운 저울을 선물해 주었다.
www.acmicpc.net
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
#define ll long long
static const auto fastio = []() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
return 0;
};
ll n, cnt;
int main() {
cin >> n;
ll s[50001];
for (ll i = 1; i < 50001; i++) s[i] = i * i;
for (ll i = 1; i < 50001; i++) {
auto iter1 = lower_bound(s + 1, s + i, i * i - n);
auto iter2 = upper_bound(s + 1, s + i, i * i - n);
if (*iter1 != *iter2) {
cout << i << "\n"; cnt++;
}
}
cout << (cnt == 0 ? "-1" : "");
return 0;
}
|
cs |
간단한 이분탐색 문제입니다.
lower_bound와 upper_bound의 특성을 활용하여 풀었습니다.