• HDU 4647 Another Graph Game 想法类


    解题思路:若没有边权,则对点权从大到小排序即可。。

    考虑边,将边权拆成两半加到它所关联的两个点的点权中即可。

    。。因为当两个人分别选择不同的点时,这一权值将互相抵消。

    以上摘自杭电的解题报告。

    至于为什么,还想得不是很清楚····

    由于在处理时使用的是整数,整数/2,当为奇数时0.5就不见了,所以直接把点的权值翻倍,最后结果除以2,这算是一个技巧吧····

    贴代码:

     1 #include <cstdio>
     2 #include <algorithm>
     3 #define N 100005
     4 using namespace std;
     5 long long int a[N];
     6 bool cmp(long long int a,long long int b)
     7 {
     8     return a > b;
     9 }
    10 int main()
    11 {
    12     int n,m;
    13     while(scanf("%d%d",&n,&m) != EOF)
    14     {
    15         for(int i=1; i<=n; ++i)
    16         {
    17             scanf("%I64d",&a[i]);
    18             a[i] *= 2;
    19         }
    20         for(int i=0; i<m; ++i)
    21         {
    22             int u,v,w;
    23             scanf("%d%d%d",&u,&v,&w);
    24             a[u] += w;
    25             a[v] += w;
    26         }
    27         sort(a+1,a+1+n,cmp);
    28         long long int ans =0;
    29         for(int i=1; i<=n; ++i)
    30         {
    31             ans  += a[i];
    32             ans  -= a[++i];
    33         }
    34         printf("%I64d
    ",ans/2);
    35     }
    36     return 0;
    37 }
    View Code
  • 相关阅读:
    php 0818
    php 0817
    python 0812
    python 0808
    python 0810
    php 0822
    python 0815
    python 0816
    微信浏览器内调取扫一扫
    linux下的socket基础编程
  • 原文地址:https://www.cnblogs.com/allh123/p/3241657.html
Copyright © 2020-2023  润新知