HDU 4647 Another Graph Game ( 贪心 +思维)

Another Graph Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2179    Accepted Submission(s): 854


Problem Description
Alice and Bob are playing a game on an undirected graph with n (n is even) nodes and m edges. Every node i has its own weight W v, and every edge e has its own weight W e.

They take turns to do the following operations. During each operation, either Alice or Bob can take one of the nodes from the graph that haven't been taken before. Alice goes first.

The scoring rule is: One person can get the bonus attached to a node if he/she have choosen that node before. One person can get the bonus attached to a edge if he/she have choosen both node that induced by the edge before.

You can assume Alice and Bob are intelligent enough and do operations optimally, both Alice and Bob's target is maximize their score - opponent's.

What is the final result for Alice - Bob.

 

Input
Muilticases. The first line have two numbers n and m.(1 <= n <= 10 5, 0<=m<=10 5) The next line have n numbers from W 1 to W n which W i is the weight of node i.(|W i|<=10 9)

The next m lines, each line have three numbers u, v, w,(1≤u,v≤n,|w|<=10 9) the first 2 numbers is the two nodes on the edge, and the last one is the weight on the edge.
 

Output
One line the final result.

 

Sample Input
 
  
4 0 9 8 6 5
 

Sample Output
 
  
2
 

Source
 

Recommend
zhuyuanchen520   |   We have carefully selected several similar problems for you:   6275  6274  6273  6272  6271 
 
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 100005
using namespace std;
int  n,m;
double node[maxn];
/*
一个无向图,边有权重,点有权重,
两个人游戏博弈,
最优策略下问两个人差值是多少

每条边如果一人占一点,则边的权重被抵消,、
按照这个思路,我们可以把每个点加上其临边的权重的一半,
这样就符合要求了,之后排序即可

*/
int main()
{
    //ios::sync_with_stdio(false);
    //cin>>n>>m;
    int u,v,i;
    double w;
    while(~scanf("%d%d",&n,&m)!=EOF)
    {
        //memset(node,0,sizeof(node));
       for(i=1;i<=n;i++) scanf("%lf",&node[i]);
       for( i=0;i<m;i++)
      {
          scanf("%d%d%lf",&u,&v,&w);
           w/=2;
          node[u]+=w;
          node[v]+=w;
      }
      sort(node+1,node+1+n);
      double ans1=0,ans2=0;
      for(i=1;i<=n;i++)
      {
          if(i%2==0)  ans1+=node[i];
          else  ans2+=node[i];
      }
      printf("%.0f\n",ans2-ans1);
      //cout<<ans2-ans1<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37451344/article/details/80272558