# Link

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

 

8983번: 사냥꾼

KOI 사냥터에는 N 마리의 동물들이 각각 특정한 위치에 살고 있다. 사냥터에 온 사냥꾼은 일직선 상에 위치한 M 개의 사대(총을 쏘는 장소)에서만 사격이 가능하다. 편의상, 일직선을 x-축이라 가

www.acmicpc.net

 

 

# Code - C++

//
//  BOJ
//  ver.C++
//
//  Created by GGlifer
//
//  Open Source

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define endl '\n'
#define len(x) (int)(x).length()
#define size(x) (int)(x).size()
#define str(x) to_string(x)
#define error logic_error("line " + str(__LINE__))

// Set up : Definitions
struct Point { int x, y; };

// Set up : Global Variables
/* None */

// Set up : Functions Declaration
/* None */


int main()
{
    // Set up : I/O
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // Set up : Input
    int M, N, L;
    cin >> M >> N >> L;
    vector<int> S(M);
    for (int i=0; i<M; i++)
        cin >> S[i];
    Point A[N];
    for (int i=0; i<N; i++)
        cin >> A[i].x >> A[i].y;

    // Process
    sort(S.begin(), S.end());

    int ans = 0;
    for (auto [ax, ay] : A) {
        auto pos = upper_bound(S.begin(), S.end(), ax);
        if (pos != end(S)) {
            int sx = *pos;
            if (abs(ax - sx) + ay <= L) {
                ans++;
                continue;
            }
        }
        if (pos != S.begin()) {
            int sx = *(--pos);
            if (abs(ax-sx) + ay <= L) {
                ans++;
                continue;
            }
        }
    }

    // Control : Output
    cout << ans << endl;
}

// Helper Functions
/* None */

 

 

지적, 조언, 첨언 모두 환영합니다!!!

+ Recent posts