首页 > 代码库 > <html>

<html>

Another Graph Game

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


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,(1≤u,v≤n,|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


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;
#define LL long long
#define maxn 100000 + 10

int n, m;
double a[maxn];

int main()
{
    while(~scanf("%d%d", &n, &m))
    {
        for(int i=1; i<=n; i++)
            scanf("%lfd", &a[i]);

        int u, v;
        double w;
        for(int i=1; i<=m; i++)
        {
            scanf("%d%d%lf", &u, &v, &w);
            w /= 2;
            a[u] += w;
            a[v] += w;
        }
        sort(a+1, a+1+n);
        double sum1 = 0, sum2 = 0;
        for(int i=n; i>=1; i--)
            {
                if(i & 1)
                    sum2 += a[i];
                else
                    sum1 += a[i];
            }
        printf("%.0lf\n", sum1 - sum2);
    }
    return 0;
}


<link rel="stylesheet" href="http://static.blog.csdn.net/public/res-min/markdown_views.css?v=1.0" />
阅读全文
版权声明:本文为博主原创文章,未经博主同意不得转载。 举报
  • 本文已收录于下面专栏:
0条评论
技术分享
发表评论
HTML/XML objective-c Delphi Ruby PHP C# C++ JavaScript Visual Basic Python Java CSS SQL 其他

相关文章推荐

hdu 4647 Another Graph Game

点击打开hdu 4647思路: 贪心1 若没有边权,则对点权从大到小排序就可以2 考虑边。将边权拆成两半加到它所关联的两个点的点权中就可以。

由于当两个人分别选择不同的点时。这一权值将互相抵消 ...

  • 技术分享
  • cgl1079743846
  • 2013-08-07 09:40
  • 788

hdu 4647 Another Graph Game

点击打开hdu 4647思路: 贪心1 若没有边权,则对点权从大到小排序就可以2 考虑边,将边权拆
  • 技术分享
  • 从此醉
  • 2013-08-07 09:40
  • 47

hdu 4647 Another Graph Game

若没有边权,则对点权从大到小排序就可以。。考虑边,将边权拆成两半加到它所关联的两个点的点权中就可以。由于当两个人分别选择不同的点时。这一权值将互相抵消。#include...
  • 技术分享
  • hlmfjkqaz
  • 2013-08-06 19:50
  • 291

hdu 1556 Color the ball 树状数组思路分析

[align=left][size=medium][color=red]网上非常多博客都仅仅给了代码。这对于非常多刚接触树状数组的人来说往往一头雾水。

我说一下主要思路:你每次更新一个点的时候(加一个数),后面全部的点的前缀和都会对应的加上这个数。这事实上就相当于这个数受了这个点影响,你每次画一个点的时候,事实上就相当于画了它后面全部的点,然后你把那些不必要画的点受的影响减回来即可[/color][/size][/align][code="C++"]#include #define lowbit(i) i&(-i)using namespace std;

  • 技术分享
  • weiqingliu
  • 2015-10-30 18:47
  • 95

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

http://acm.hdu.edu.cn/showproblem.php?pid=4647Another?Graph?GameTime?Limit:?2000/1000?MS?(Java...
  • 技术分享
  • JHC23
  • 2013-08-16 21:15
  • 503

hdu 1423 Greatest Common Increasing Subsequence 题解

[code="C++"]#include #include #include #include #include using namespace std;int dp[550];int T;int a[550],b[550];int main(){ scanf("%d",&T); int m,n; while(T--) { scanf("%d",&m); for(int i=1; i<=m
  • 技术分享
  • weiqingliu
  • 2015-07-25 20:38
  • 84

hdu 4647 - Another Graph Game(思路题)

摘自题解:若没有边权。则对点权从大到小排序就可以。。考虑边,将边权拆成两半加到它所关联的两个点的点权中就可以。。。由于当两个人分别选择不同的点时,这一权值将互相抵消。代码例如以下:#i...
  • 技术分享
  • shankeliupo
  • 2013-08-06 19:51
  • 404

[HDU][线段树]1166.敌兵布阵

Problem Description C国的死对头A国这段时间正在进行军事演习。所以C国间谍头子Derek和他手下Tidy又開始忙乎了。

A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。因为採取了某种先进的监測手段,所以每一个工兵营地的人数C国都掌握的一清二楚,每一个工兵营地的人数都有可能发生变动,可能添加或降低若干人手,但这些都逃只是C国的监视。 中央情报局要研究敌人到底演习什么战术,所以Tidy要随时向Derek汇报某一段

  • 技术分享
  • SunnyYoona
  • 2015-03-24 15:51
  • 28

hdu - 4647 - Another Graph Game(切割权)

题意:n个点m条边。每一个点有权值,每条边也有权值,权值的范围是 |w| 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4647 ——>>对于边权,把这...
  • 技术分享
  • SCNU_Jiechao
  • 2013-08-06 21:36
  • 910

hdu 5510 Bazinga 思路具体解释 kmp +思维

[size=large]来一发代码。先前后两两比較,假设前一个串是后一个串的字串,那他就是不是必需的,假设第i个串是i+1的子串。假设在后面循环比較中。假设第i+1个串是后面串的子串。那i个串就没有比的必要了,假设第i+1不是后面串的子串。直接结束循环。查找结束。得出结果[/size][code="C++"]#include int next[10005];int T;char s[505][2005];bool v[550],flag;void getnext(char str[],int len){ int k=
  • 技术分享
  • weiqingliu
  • 2015-11-01 19:32
  • 176