zoukankan      html  css  js  c++  java
  • 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): 660    Accepted Submission(s): 235


    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
    题意: 有N个点,M条边。 点有权值, 边有权值。 Alice, Bob 分别选点。 如果一条边的两个顶点被同一个人选了, 那么能获得该权值。问 Alice - Bob?
    分析:贪心,如没有边权,则对点权进行从大到小排序即可,加入边权之后,将边权拆分两半之后加到他所关联的两个点权中即可,这样,当两个人分别选择同边的两个点时,
    相互抵消,一个人选了同边的两个点时,边权也都加进去了。。。
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 using namespace std;
     6 
     7 const int maxn = 1e5+10;
     8 double a[maxn];
     9 bool cmp(double x,double y){
    10     return x>y;
    11 }
    12 
    13 int main(){
    14     int n,m;
    15     while(~scanf("%d%d",&n,&m)){
    16         for( int i=1; i<=n; i++ ){
    17             scanf("%lf",&a[i]);
    18         }
    19         int u,v,w;
    20         while(m--){
    21             cin>>u>>v>>w;
    22             a[u]+=1.0*w/2;
    23             a[v]+=1.0*w/2;
    24         }
    25         double t1=0,t2=0;
    26         sort(a+1,a+1+n,cmp);
    27         for( int i=1; i<=n; i++ ){
    28             if(i%2==1){/*等同于 i&1 */
    29                 t1+=a[i];
    30             }
    31             else{
    32                 t2+=a[i];
    33             }
    34         }
    35         printf("%.01f
    ",t1-t2);
    36     }
    37     return 0;
    38 }    
    有些目标看似很遥远,但只要付出足够多的努力,这一切总有可能实现!
  • 相关阅读:
    07.对称加密算法指令
    06.Openssl基本概念
    04.openssl背景
    03.openssl密码实现技术
    02.密钥学基本概念
    01.openssl-概述
    17行为型模式之命令模式
    16行为型模式之模板模式
    15结构型模式之享元模式
    14结构型模式之外观模式
  • 原文地址:https://www.cnblogs.com/Bravewtz/p/10386922.html
Copyright © 2011-2022 走看看