ABC317

发布时间 2023-09-02 00:28:40作者: V_Melville

T1:Potions

模拟

代码实现
n, h, x = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
    if h+p[i] >= x:
        exit(print(i+1))

T2:MissingNo.

不妨假设丢失的整数不是其中的最小数,然后用 std::set 来找出那个丢失的数即可

代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main() {
    int n;
    cin >> n;
    
    set<int> s;
    rep(i, n) {
        int a;
        cin >> a;
        s.insert(a);
    }
    
    int x = *s.begin();
    while (s.count(x)) ++x;
    
    cout << x << '\n';
    
    return 0;
}

T3:Remembering the Days

暴力枚举

代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    
    vector<vector<array<int, 2>>> g(n);
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        g[a].push_back({b, c});
        g[b].push_back({a, c});
    }
    
    int ans = 0;
    vector<bool> used(n);
    auto f = [&](auto f, int v, int dist) -> void {
        used[v] = true;
        ans = max(ans, dist);
        for (auto [u, w] : g[v]) {
            if (used[u]) continue;
            f(f, u, dist+w);
        }
        used[v] = false;
    };
    
    rep(i, n) f(f, i, 0);
    
    cout << ans << '\n';
    
    return 0;
}