• CodeForces-437C(贪心)


    链接:

    https://vjudge.net/problem/CodeForces-437C

    题意:

    On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.

    The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.

    Help the child to find out, what is the minimum total energy he should spend to remove all n parts.

    思路:

    优先选值较大的点去拿,这样值较大的点就被累加的次数小.

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <vector>
    //#include <memory.h>
    #include <queue>
    #include <set>
    #include <map>
    #include <algorithm>
    #include <math.h>
    #include <stack>
    #include <string>
    #include <assert.h>
    #define MINF 0x3f3f3f3f
    using namespace std;
    typedef long long LL;
    
    const int MAXN = 1e3+10;
    struct Node
    {
        int v;
        int pos;
        bool operator < (const Node& that) const
        {
            return this->v > that.v;
        }
    }node[MAXN];
    int Map[MAXN][MAXN];
    int Val[MAXN];
    int n, m;
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin >> n >> m;
        for (int i = 1;i <= n;i++)
        {
            cin >> node[i].v;
            Val[i] = node[i].v;
            node[i].pos = i;
        }
        int u, v;
        for (int i = 1;i <= m;i++)
        {
            cin >> u >> v;
            Map[u][v] = 1;
            Map[v][u] = 1;
        }
        sort(node+1, node+1+n);
        int res = 0;
        for (int i = 1;i <= n;i++)
        {
            for (int j = 1;j <= n;j++)
            {
                if (Map[node[i].pos][j])
                {
                    res += Val[j];
                    Map[node[i].pos][j] = Map[j][node[i].pos] = 0;
                }
            }
        }
        cout << res << endl;
    
        return 0;
    }
    
  • 相关阅读:
    编写有效事务的指导原则
    ReadUnCommitted与ReadCommitted
    用Delphi 、VB.net以及C#混合编程
    查询未提交事务个数
    输入法的切换问题
    有关数据死锁问题的一篇好文章,一个好博客
    同一连接内事务名只有一个
    无法运行16位应用程序
    查看长时间运行的事务
    在TSQL中使用临时表的注意事项
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11368350.html
Copyright © 2020-2023  润新知