프로그래밍 공부

BOJ/백준 7568 덩치 본문

Problem Solving/Baekjoon Online Judge

BOJ/백준 7568 덩치

khj1999 2021. 7. 21. 13:25

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

 

7568번: 덩치

우리는 사람의 덩치를 키와 몸무게, 이 두 개의 값으로 표현하여 그 등수를 매겨보려고 한다. 어떤 사람의 몸무게가 x kg이고 키가 y cm라면 이 사람의 덩치는 (x, y)로 표시된다. 두 사람 A 와 B의 덩

www.acmicpc.net

 

언어 : C++17

환경 : VSCode gcc 8.1.0

 

알고리즘

문제 그대로 모든 경우를 비교 하여 등수를 매겨 주면된다 2중 for문을 사용하여 선택한 사람 보다,

덩치가 큰 사람이 있으면 등수를 올려준다.

코드

#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second

bool solve(pair<int, int> x, pair<int, int> y){
    if (x.X > y.X && x.Y > y.Y) return true;
    else if(x.X >= y.X || x.Y >= y.Y) return true;
    else return false;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    vector<pair<int,int>> v,copy;
    int n;
    cin >> n;
    for(int i = 0; i < n ; i++){
        int x, y;
        cin >> x >> y;
        v.push_back({x,y});
    }
    copy = v;
    for(auto i : v){
        int cnt = 1;
        for(auto j : copy){
            if(!solve(i,j)) cnt++;
        }
        cout << cnt << ' ';
    }
    return 0;
}

 

결과

Comments