2563: 阿狸和桃子的游戏 贪心

本文探讨了在一个特定的无向图中,两个玩家如何通过选择节点来最大化自己得分减去对手得分的策略。通过调整点权和边权,文章提出了一种基于贪心策略的解决方案,展示了算法设计中博弈论的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description
给定一张无向图,每个点有点权,每条边有边权,两个人轮流选择点,若一条边的两端点被选择则这条边被选择,两人都想自己的得分-对手的得分最大,求最终先手得分-后手得分


Sample Input
4 4
6
4
-1
-2
1 2 1
2 3 6
3 4 3
1 4 5


Sample Output
3


贪心好题,并不会做。
大家去膜PoPoQQQ吧。。。
世界


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
int read() {
	int s = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * f;
}

int a[11000];

int main() {
	int n = read(), m = read();
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		int c = read();
		a[i] += c * 2;
		ans -= c;
	}
	for(int i = 1; i <= m; i++) {
		int x = read(), y = read(), c = read();
		a[x] += c, a[y] += c;
		ans -= c;
	} sort(a + 1, a + n + 1);
	for(int i = n; i >= 1; i -= 2) ans += a[i];
	printf("%d\n", ans);
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值