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): 601    Accepted Submission(s): 216


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
 

Recommend
zhuyuanchen520
 

題意: 有N個點,M條邊。 點有權值, 邊有權值。 Alice, Bob 分別選點。 如果一條邊的兩個頂點被同一個人選了, 那麼能獲得該權值。問 Alice - Bob?

思路: 貪心。
對於一條邊來說, 如果拿了一個點, 說明已經拿了該邊的一半權值。
如果某邊的兩個的頂點分別是不同的人。  那麼差值還是不變的。 
如果某邊的兩個頂點分別是同一個人。 那麼和值也不變。
所以我們可以把一個邊分解到兩個頂點上。
然後依次Alice 取最大,Bob 取次大。 因爲 他們都是絕頂聰明的。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

//

const int V = 100000 + 50;
const int MaxN = 80 + 5;
const int mod = 10000 + 7;
const __int64 INF = 0x7FFFFFFFFFFFFFFFLL;
const int inf = 0x7fffffff;
int n, m, ans;
double num[V];
bool cmp(__int64 a, __int64 b) {
    return a > b;
}
int main() {
    int i, j;
    while(~scanf("%d%d", &n, &m)) {
        for(i = 1; i <= n; ++i)
            scanf("%lf", &num[i]);
        while(m--) {
            int u, v, w;
            scanf("%d%d%d", &u, &v, &w);
            num[u] += w / 2.0;
            num[v] += w / 2.0;
        }
        sort(num + 1, num + n + 1, cmp);
        double a, b;
        a = b = 0.0;
        for(i = 1; i <= n; ++i) {
            if(i % 2 == 1)
                a += num[i];
            else
                b += num[i];
        }
        printf("%I64d\n", (__int64)(a - b));
    }
}

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章