跳到正文

个人记录

YL9/22总结

wys2023约 8 分钟
原文
文章信息与版本

文章信息

发布
2025年9月22日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 8 分钟

版本

  1. v1当前

YL9/22总结

A

这题意绝对是有史以来最清晰的

思路:

由于按顺序1-n又n-1,所以每两个点间一定会走两次,枚举取min即可。

错因:

——————

代码:

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

int n,m;
struct node
{
    long long x,y;
}a[200005];

int main()
{
    freopen("treacat.in","r",stdin);
    freopen("treacat.out","w",stdout);
    cin >> n >> m;
    for(int i = 1,j = 2;i <= 2 * n - 1;i += 2,j += 2)
    {
        cin >> a[i].x >> a[i].y;
        cin >> a[j].x >> a[j].y;
    }
    long long ans = 0;
    for(int i = 1,j = 2;i <= 2 * n - 3;i += 2,j += 2)
    {
        long long minn = 1e18;
        minn = min(minn,abs(a[i].x - a[i + 2].x) + abs(a[i].y - a[i + 2].y) + abs(a[j].x - a[j + 2].x) + abs(a[j].y - a[j + 2].y));
        minn = min(minn,abs(a[i].x - a[j + 2].x) + abs(a[i].y - a[j + 2].y) + abs(a[i + 2].x - a[j].x) + abs(a[i + 2].y - a[j].y));
        ans += minn;
    }
    ans += abs(a[2 * n].x - a[2 * n - 1].x) + abs(a[2 * n].y - a[2 * n - 1].y);
    cout << ans << endl;
    return 0;
}

B

思路:

最短路板子,但是考试时测了大样例没测小样例挂了。

错因:

没有判0,初始化问题。

代码:

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

long long n,m,k,h[1000005];
struct bi
{
    long long id,x;
};
vector <bi> v[1000005];
struct node
{
    long long x,dist;
    bool operator <(const node & x) const
    {
        return dist < x.dist;
    }
};
long long dis[1000005];
bool f[1000005];
void dij()
{
    priority_queue <node> q;
    for(int i = 1;i <= n;i++) dis[i] = 1e18;
    dis[1] = 0;
    q.push({1,0});
    h[1] += k;
    while(q.size() > 0)
    {
        int x = q.top().x,w = q.top().dist;
        q.pop();
        if(f[x]) continue;
        f[x] = true;
        for(auto i:v[x])
        {
            if(dis[x] + i.x + max(0ll,h[i.id] - h[1]) * max(0ll,h[i.id] - h[1]) < dis[i.id])
            {
                dis[i.id] = dis[x] + i.x + max(0ll,h[i.id] - h[1]) * max(0ll,h[i.id] - h[1]);
//              cout << i.id << " " << dis[i.id] << endl;
                q.push({i.id,-dis[i.id]});
            }
        }
    }
    cout << dis[n] << endl;
}

int main()
{
 //   freopen("climb.in","r",stdin);
   // freopen("climb.out","w",stdout);
    cin >> n >> m >> k;
    for(int i = 1;i <= n;i++) cin >> h[i];
    for(int i = 1;i <= m;i++)
    {
        int x,y,z;
        cin >> x >> y >> z;
        v[x].push_back({y,z});
        v[y].push_back({x,z});
    }
    dij();
    return 0;
}

C

思路:

dp前i个数的方案即可。

错因:

思路问题。

代码:

C++
//bu yao T bu yao T bu yao T bu yao T bu yao T bu yao T bu yao T
#include <bits/stdc++.h>
#define LL long long

using namespace std;

const LL N = 1e4 + 5, mod = 1e9 + 7;

LL n, f[N], qwq[N][2];

LL qpow (LL x, LL y) {
    LL ret = 1;
    for (; y; y >>= 1) {
        if (y & 1) {
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
    }
    return ret;
}

LL C (LL x, LL y) {
    return qwq[x][0] * qwq[x - y][1] % mod * qwq[y][1] % mod;
}

int main () {
    freopen("perm.in", "r", stdin);
    freopen("perm.out", "w", stdout);
    cin >> n;
    qwq[0][0] = qwq[0][1] = 1;
    for (LL i = 1; i <= n; i++) {
        qwq[i][0] = qwq[i - 1][0] * i % mod;
        qwq[i][1] = qpow(qwq[i][0], mod - 2);
    }
    f[0] = f[1] = 1;
    for (int i = 2; i <= n; i++) {
        for (int j = 1; j <= i; j += 2) {
            f[i] += f[j - 1] * f[i - j] % mod * C(i - 1, j - 1) % mod;
            f[i] %= mod;
        }
    }
    cout << f[n];
    return 0;
}



























































































































原文