GESP2026年3月游记

· · 生活·游记

这一天,我去考了GESP七级。 编程题第一题我直接一眼出答案,无脑数学题一道。 前桌那傻der还在用DP呢,笑死人了,是不是脑子进水了啊。 第二题史山代码过了两个点,加几个特判又过一个点,简单。 不过洛谷分数少了很多,€€£的数据还是太水了啊。 开心开心开心,轻松轻松轻松,好玩好玩好玩。
第一题代码:AC 100

#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9;

long long qpow(long long a, long long b) {
    a %= mod;
    long long ans = 1;
    while (b != 0) {
        if (b % 2 == 1) {
            ans = ((ans % mod) * a) % mod;
        }
        b /= 2;
        a = a * a % mod;
    }
    return ans % mod;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        long long n;
        cin >> n;
        if (n <= 4) {
            cout << n << endl;
            continue;
        }
        if (n % 3 == 0) {
            cout << qpow(3, n / 3) << endl;
        } else if (n % 3 == 1) {
            cout << (qpow(3, n / 3 - 1) * 4) % mod << endl;
        } else {
            cout << (qpow(3, n / 3) * 2) % mod << endl;
        }
    }
    return 0;
}

第二题代码:WA 4

#include <bits/stdc++.h>
using namespace std;

struct road {
    long long v, w, b;
};

struct node {
    long long c, z;
} a[5005];
long long n, m, dis[5005];
vector<road>g[5005];
bool vis[5005];
queue<long long>q;

void bfs(int u) {
    q.push(u);
    vis[u] = 1;
    while (!q.empty()) {
        for (auto i : g[u]) {
            if (vis[i.v] != 1) {
                q.push(i.v);
                vis[i.v] = 1;
                dis[i.v] = dis[u] + i.w;
                if (a[i.v].c < i.b) {
                    a[i.v].c = i.b;
                    a[i.v].z = i.w;
                }
            }
        }
    }
}

int main() {
    cin >> n >> m;
    for (long long i = 1; i <= n; i++) {
        long long u, v, w, b;
        cin >> u >> v >> w >> b;
        g[u].push_back({v, w, b});
        g[v].push_back({u, w, b});
    }
    if (n == 1) {
        cout << 0;
        return 0;
    }
    if (dis[n] == 0 && n != 1) {
        cout << -1;
        return 0;
    }
    for (auto i : g[1]) {
        if (i.v == n) {
            cout << 0;
            return 0;
        }
    }
    cout << dis[n] - a[n].z;
    return 0;
}

拆分 题解
代码仅供参考,请勿抄袭!