【題解】AtCoder ABC 170C – Forbidden List

【題目敘述 】https://atcoder.jp/contests/abc170/tasks/abc170_c

#include <iostream>
#include <set>
using namespace std;
 
int x, n, a, mn, ans;
set <int> st;
 
int main() {
    cin >> x >> n;
    for (int i = 0; i < n; i++){
        cin >> a;
        st.insert(a);
    }
    mn = 1000;
    for (int i = 0; i <= 101; i++){
        if (st.count(i)) continue;
        if (abs(i-x) < mn){
            mn = abs(i-x);
            ans = i;
        }
    }
    cout << ans << "\n";
}
分享本文 Share with friends