HDU4647:Another Graph Game(贪心)

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
题意:
对于一个图,两个人轮流取点,谁取得那个点则获得那个点的价值,而一个人如果取得同一条边的两点,则同时也会获得这条边的价值,两人都按最优方案去取,最后输出价值之差
思路:
只要将边分半给两个点即可,如果两点同时在一个人身上,那么边的价值也会加上去,如果两点在两个人身上,那么边的价值会被减去
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;

#define ls 2*i
#define rs 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define N 100005
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define rank rank1
const int mod = 10007;

int n,m;
double a[N];

int main()
{
    int i,j,k,x,y;
    double w;
    while(~scanf("%d%d",&n,&m))
    {
        for(i = 1; i<=n; i++)
            scanf("%lf",&a[i]);
        for(i = 1; i<=m; i++)
        {
            scanf("%d%d%lf",&x,&y,&w);
            w=w/2;
            a[x]+=w;
            a[y]+=w;
        }
        sort(a+1,a+1+n);
        double sum1=0,sum2=0;
        for(i = 1; i<=n; i++)
        {
            if(i%2==0)
                sum1+=a[i];
            else
                sum2+=a[i];
        }
        printf("%.0f\n",sum1-sum2);
    }

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值