안녕하세요. 오늘은 기차역을 찾을거예요.

문제

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

아이디어

말이 꼬여있지만 그냥 최남단역을 찾으라는 뜻입니다. 또한 그러한 역은 유일함을 설명한 것입니다.
y좌표의 최솟값이 있는 역을 출력해줍시다.

소스코드

#include <iostream>
using namespace std;

int main(void)
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    pair <int, int> ans = { 2e9,2e9 };
    int x, y, N, i;

    cin >> N;
    for (i = 0; i < N; i++)
    {
        cin >> x >> y;
        if (y < ans.second)
            ans = { x,y };
    }
    cout << ans.first << ' ' << ans.second << "\n";
}


감사합니다.

0개의 댓글