HDU 4647 Another Graph Game 思路+贪心

官方题解:

若没有边权,则对点权从大到小排序即可。。

考虑边,将边权拆成两半加到它所关联的两个点的点权中即可。

。。因为当两个人分别选择不同的点时,这一权值将互相抵消。

 

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <algorithm>



using namespace std;



const int MAXN = 100010;



int N, M;

double node[MAXN];



int main()

{

    while ( ~scanf( "%d%d", &N, &M ) )

    {

        for ( int i = 1; i <= N; ++i )

            scanf( "%lf", &node[i] );



        for ( int i = 0; i < M; ++i )

        {

            int u, v, w;

            scanf( "%d%d%d", &u, &v, &w );

            node[u] += w / 2.0;

            node[v] += w / 2.0;

        }



        sort( node + 1, node + N + 1 );



        double Alice = 0.0, Bob = 0.0;

        for ( int i = 1; i <= N; ++i )

        {

            if ( !(i & 1) )

                Alice += node[i];

            else Bob += node[i];

        }

        printf( "%.0f\n", Alice - Bob );

    }

    return 0;

}

 

你可能感兴趣的:(Graph)