hdu 4647 Another Graph Game
思路:若没有边权,则对点权从大到小排序即可,考虑边,将边权拆成两半加到它所关联的两个点的点权中即可,因为当两个人分别选择不同的点时,这一权值将互相抵消。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; double val[100010]; int cmp(double a,double b) { return a>b; } int main() { int n,i,m,j,a,b; double c; while(scanf("%d%d",&n,&m)!=EOF) { for(i=1;i<=n;i++) scanf("%lf",val+i); for(i=1;i<=m;i++) { scanf("%d%d%lf",&a,&b,&c); val[a]+=c/2; val[b]+=c/2; } sort(val+1,val+n+1,cmp); double Alice,Bob; Alice=Bob=0; for(i=1;i<=n;i++) { if(i%2) Alice+=val[i]; else Bob+=val[i]; } printf("%I64d\n",(__int64)(Alice-Bob)); } return 0; }