• 2020杭电多校第二场


    1001.Total Eclipse

    每次选择最大连通块,将所有值同时减小,减小到零断开。

    换种思路,将所有数从大到小排序,依次将点加入图,加入后将所有值的权值降至下一个数的大小

    此时答案为 (b[i]-b[i+1])*当前图的连通块个数,对每次加点维护一个连通块个数即可

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define rep(i, a, b) for (register int i = a; i <= b; i++)
    
    struct point
    {
        int id, w;
        bool operator<(point &f) const { return w > f.w; }
    } a[100010];
    vector<int> son[100010];
    int n, m, u, v;
    ll ans, block;
    int pre[100010];
    int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); }
    void solve()
    {
        cin >> n >> m;
        rep(i, 1, n)
        {
            cin >> a[i].w;
            a[i].id = i;
            son[i].clear();
            pre[i] = i;
        }
        rep(i, 1, m)
        {
            cin >> u >> v;
            if (a[u].w < a[v].w)
                son[u].push_back(v);
            else
                son[v].push_back(u);
        }
        sort(a + 1, a + n + 1);
        a[n + 1].w = 0;
        ans = block = 0;
        rep(i, 1, n)
        {
            int root = find(a[i].id);
            block++;
            for (vector<int>::iterator it = son[a[i].id].begin(); it != son[a[i].id].end(); it++)
            {
                int root2 = find(*it);
                if (root2 != root)
                {
                    block--;
                    pre[root2] = root;
                }
            }
            ans += block * (a[i].w - a[i + 1].w);
        }
        cout << ans << endl;
    }
    
    int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    
        int t = 1;
        cin >> t;
        while (t--)
        {
            solve();
        }
    }
    View Code

    1006.The Oculus

    修改的那一位斐波拉契数为f[k],满足A*B==C+f[k]

    在f[1],f[2]...f[2000000]%mod不同余的时候就能找到唯一的k

    题解mod取264,不太明白为什么

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define rep(i, a, b) for (register int i = a; i <= b; i++)
    
    unsigned long long f[2000010], a[3];
    int n, x;
    void solve()
    {
        a[0] = a[1] = a[2] = 0;
        rep(i, 0, 2)
        {
            cin >> n;
            rep(j, 1, n)
            {
                cin >> x;
                if (x)
                    a[i] += f[j];
            }
        }
        for (int i = 1;; i++)
            if (a[0] * a[1] - a[2] == f[i])
            {
                cout << i << endl;
                break;
            }
    }
    
    int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    
        f[1] = 1;
        f[2] = 2;
        rep(i, 3, 2000000) f[i] = f[i - 2] + f[i - 1];
    
        int t = 1;
        cin >> t;
        while (t--)
        {
            solve();
        }
    }
    View Code

    1010.Lead of Wisdom

    暴搜。。。我去除了比某一同类装备4个属性都低的装备

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define rep(i, a, b) for (register int i = a; i <= b; i++)
    
    typedef struct clo
    {
        int a, b, c, d;
    } cloth;
    int n, k, A, B, C, D, T;
    ll ans;
    vector<cloth> p[55];
    void dfs(int x, int a, int b, int c, int d)
    {
        while (x <= k && p[x].empty())
            x++;
        if (x > k)
        {
            ans = max(ans, 1ll * a * b * c * d);
            return;
        }
        for (vector<cloth>::iterator it = p[x].begin(); it != p[x].end(); it++)
            dfs(x + 1, a + (*it).a, b + (*it).b, c + (*it).c, d + (*it).d);
    }
    inline void solve()
    {
    
        cin >> n >> k;
        rep(i, 1, k) p[i].clear();
        ans = 100000000;
        rep(i, 1, n)
        {
            cin >> T >> A >> B >> C >> D;
            int flag = 1;
            for (vector<cloth>::iterator it = p[T].begin(); it != p[T].end(); it++)
            {
                if (A <= (*it).a && B <= (*it).b && C <= (*it).c && D <= (*it).d)
                {
                    flag = 0;
                    break;
                }
            }
            if (flag)
                p[T].push_back({A, B, C, D});
        }
        dfs(1, 100, 100, 100, 100);
        cout << ans << endl;
    }
    
    int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    
        int t = 1;
        cin >> t;
        while (t--)
        {
            solve();
        }
    }
    View Code
  • 相关阅读:
    初识 vue
    Spring boot 整合 Swagger
    Swagger 注解
    初识 Swagger
    初识 mycat
    SpringBoot中的国际化
    为什么博客园用户体验这么差?
    Numpy常用方法及应用总汇
    嵌入式开发10种常见数字滤波算法
    .gitignore使用
  • 原文地址:https://www.cnblogs.com/likunhong/p/13368606.html
Copyright © 2020-2023  润新知