Another Graph Game(hdu4647,拆边+贪心)

73 篇文章 0 订阅
10 篇文章 0 订阅


http://acm.hdu.edu.cn/showproblem.php?pid=4647
Another Graph Game

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


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 Wv, and every edge e has its own weight We.

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 <= 105, 0<=m<=105) The next line have n numbers from W1 to Wn which Wi is the weight of node i.(|Wi|<=109)

The next m lines, each line have three numbers u, v, w,(1u,vn,|w|<=109) 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
2013 Multi-University Training Contest 5

Recommend
zhuyuanchen520

Statistic | Submit | Discuss | Note
解析:
题意:
每个点和每条路段都有权值,A,B两个人轮流取点,A先开始,取得的点就可以获得点上的权值,
并且如果一条边的两个点是同一个人取的话,那么那个人就可以得到该边的权值。求两人获得的最大权值差
思路:
处理边。把边上的权值各分给两个点一半,(计算结果只是算权值差,当一条边上不同人取时自然就把边权消去,同一个人的话则边权存在且被加)计算时不不计边。只需将点按照权值从小到大排序,A,B 轮流取。
4647 234MS 1024K 658 B C++ jingzuo
*/

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include <iostream>
using namespace std;
const int maxn=100010;
double node[maxn];
bool cmp(double a,double b)
{
return a>b;
}
int main()
{
   int n,m,i,j,u,v;
   double w,ans;
   while(scanf("%d%d",&n,&m)!=EOF)
   {
    memset(node,0,sizeof(node));
    for(i=0;i<n;i++)
     scanf("%lf",&node[i]);
     for(j=0;j<m;j++)
 {
  scanf("%d%d%lf",&u,&v,&w);
  node[u-1]+=w/2.0;
  node[v-1]+=w/2.0;
 }
 sort(node,node+n,cmp);
 ans=0;
 for(i=0;i<n;i++)
 {  if(i%2==0)
  ans+=node[i];
  else
  ans-=node[i];
 }
 printf("%.0lf\n",ans);
   }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值