Luogu P4643 阿狸和桃子的游戏

题解 传送门

既然题目要求的是差值
所以对于减数和被减数同时加上一个相同的数是毫无影响的 (详情参考人教版六年级上册数学教材)
所以不妨把边权分成两半
分别加给两个顶点
然后,直接每次选最大的点就好了

代码

#include<bits/stdc++.h>
using namespace std;
#define re register
#define ll long long
#define in inline
#define get getchar()
#define db double
in int read()
{
    int t=0,x=1; char ch=get;
    while ((ch<'0' || ch>'9') && ch!='-') ch=get;
    if (ch=='-') ch=get,x=-1;
    while (ch<='9' && ch>='0') t=t*10+ch-'0',ch=get;
    return t*x;
}
const int _=1e5+5;
db w[_];
int n,m;
int main()
{
    n=read(),m=read();
    for(re int i=1;i<=n;i++)
        w[i]=read();
    for(re int i=1;i<=m;i++)
    {
        db x=read(),y=read(),z=read();
        w[int(x)]=w[int(x)]+(z/2),w[int(y)]=w[int(y)]+(z/2);
    }
    sort(w+1,w+n+1);
    db sum1=0,sum2=0;
    for(re int i=n;i>=1;i--)
    {
        if(i%2==n%2)
            sum1+=w[i]; //阿狸先行动
        else
            sum2+=w[i]; //桃子再行动
    }
    cout<<sum1-sum2<<endl;
    return 0;
}

转载于:https://www.cnblogs.com/yzhx/p/10655608.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值