hdu 4647
来源:互联网 发布:网络词吃狗粮的意思 编辑:程序博客网 时间:2024/06/15 14:39
Another Graph Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1691 Accepted Submission(s): 630
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.
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.
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 09 8 6 5
Sample Output
2
Source
2013 Multi-University Training Contest 5
#include <iostream>#include <cstdio>#include <string>#include <algorithm>using namespace std;#define LL long long#define maxn 100000 + 10int n, m;double a[maxn];int main(){ while(~scanf("%d%d", &n, &m)) { for(int i=1; i<=n; i++) scanf("%lfd", &a[i]); int u, v; double w; for(int i=1; i<=m; i++) { scanf("%d%d%lf", &u, &v, &w); w /= 2; a[u] += w; a[v] += w; } sort(a+1, a+1+n); double sum1 = 0, sum2 = 0; for(int i=n; i>=1; i--) { if(i & 1) sum2 += a[i]; else sum1 += a[i]; } printf("%.0lf\n", sum1 - sum2); } return 0;}
1 0
- HDU-4647
- hdu 4647
- hdu 4647
- hdu 4647(贪心?!)
- hdu 4647(简单贪心)
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- Sobel(索贝尔)边缘检测算子分析及opencv程序测试
- 如何让tomcat自动部署web项目
- TableView和ListView的使用
- ImageView---拍照或从相册取图片并裁剪
- SQL Server 2008数据库被标记为可疑的解决方法
- hdu 4647
- 带你了解什么时候用HashSet、TreeSet、LinkedHashSet、EnumSet
- LeetCode237:Delete Node in a Linked List
- shiro限制重复账号登陆
- 正则表达式 学习笔记
- [leetcode] 217.Contains Duplicate
- 冒泡排序
- 2012年5月SAT香港真题解析
- Jersery——RESTful Web Services in Java,RESTful服务,Jersey+Spring实现REST服务调用