# Link

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

 

1337번: 올바른 배열

첫째 줄에 배열의 크기 N이 주어진다. N은 50보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에 배열의 원소가 한 줄에 하나씩 주어진다. 원소는 1,000,000,000보다 작거나 같은 음이 아닌 정수이

www.acmicpc.net

 

 

# Code - C++

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

#include <iostream>
#include <algorithm>

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
/* None */

// 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 N; cin >> N;
    int A[N];
    for (int i=0; i<N; i++)
        cin >> A[i];

    // Process
    sort(A, A+N);
    int ans = 4;
    for (int i=0; i<N; i++) {
        int tmp = distance(A+i, lower_bound(A, A+N, A[i]+5));
        ans = min(ans, 5-tmp);
    }

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

// Helper Functions
/* None */

 

 

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

# 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 */

 

 

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

# Link

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

 

2075번: N번째 큰 수

첫째 줄에 N(1 ≤ N ≤ 1,500)이 주어진다. 다음 N개의 줄에는 각 줄마다 N개의 수가 주어진다. 표에 적힌 수는 -10억보다 크거나 같고, 10억보다 작거나 같은 정수이다.

www.acmicpc.net

 

 

# Code - C++

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

#include <iostream>
#include <queue>

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
/* None */

// 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 N; cin >> N;
    priority_queue<int,vector<int>,greater<>> pq;
    for (int i=0; i<N; i++) {
        int num; cin >> num;
        pq.push(num);
    }

    for (int i=0; i<N-1; i++) {
        for (int j=0; j<N; j++) {
            int num; cin >> num;

            // Process
            if (num > pq.top()) {
                pq.pop();
                pq.push(num);
            }
        }
    }

    // Control : Output
    cout << pq.top() << endl;
}

// Helper Functions
/* None */

 

 

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

+ Recent posts