\(N\)의 범위가 최대 50이기 때문에, 겁 먹지 말고 브루트 포스로 \(O(n^2)\)에 해결하자.
문제에서 원하는 대로 구현만 해주면 쉽게 해결 가능하다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
const int MAX = 10e+8;
ll gcd(ll a, ll b) { for (; b; a %= b, swap(a, b)); return a; }
int cnt[51] = { 0, }; // 나보다 덩치가 큰 사람의 명수를 담는 배열
pair<int, int> spec[51]; // 나의 키, 몸무게 저장
int main() {
ios::ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> spec[i].first >> spec[i].second;
for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) {
// i가 j보다 덩치가 큰 경우
if (spec[i].first > spec[j].first && spec[i].second > spec[j].second) cnt[j]++;
// i보다 j가 덩치가 큰 경우
else if (spec[i].first < spec[j].first && spec[i].second < spec[j].second) cnt[i]++;
}
for (int i = 0; i < n; i++) cout << cnt[i] + 1 << ' ';
return 0;
}
'BOJ_단계별로 풀어보기(9단계~) > [10단계] 브루트 포스' 카테고리의 다른 글
[백준 1436] 영화감독 숌 (0) | 2022.03.03 |
---|---|
[백준 1018] 체스판 다시 칠하기 (0) | 2022.03.03 |
[백준 2231] 분해합 (0) | 2022.03.03 |
[백준 2798] 블랙잭 (0) | 2022.03.02 |