解题报告 之 WHU1124 Football Coach

解题报告 之 WHU1124 Football Coach


Description
It is not an easy job to be a coach of a football team. The season is almost over, only a few matches are left to play. All of sudden the team manager comes to you and tells you bad news: the main sponsor of your club is not happy with your results and decided to stop sponsoring your team, which probably means the end of your club. The sponsor's decision is final and there is no way to change it unless... unless your team miraculously wins the league. The manager left you in deep thought. If you increase the number of practices and offer players a generous bonus for each match, you may be able to win all the remaining matches. Is that enough? You also have to make sure that teams with many points lose against teams with few points so that in the end, your team will have more points than any other team. You know some of the referees and can bribe them to manipulate the result of each match. But first you need to figure out how to manipulate the results and whether it is possible at all. There are N teams numbered 1 through N, your team has the number N. The current number of points of each team and the list of remaining matches are given. Your task is to find out whether it is possible to manipulate each remaining match so that the team N will finish with strictly more points than any other team. If it is possible, output "YES", otherwise, output "NO". In every match, the winning team gets 2 points, the losing team gets 0. If the match ends with a draw, both teams get 1 point. 

Input
There will be multiple test cases. Each test case has the following form: The first line contains two numbers N(1 <= N <= 100) and M(0 <= M <= 1000). The next line contains N numbers separated by spaces giving the current number of points of teams 1, 2, ..., N respectively. The following M lines describe the remaining matches. Each line corresponds to one match and contains two numbers a and b (a not equal to b, 1 <= a,b <= N) identifying the teams that will play in the given match. There is a blank line after each test case.

Output
For each test case, output "YES" or "NO" to denote whether it's possible to manipulate the remaining matches so that the team N would win
the league.

Sample Input
5 8
2 1 0 0 1
1 2
3 4
2 3
4 5
3 1
2 4
1 4
3 5
5 4
4 4 1 0 3
1 3
2 3
3 4
4 5

Sample Output
YES
NO


首先吐槽终于找到可以撼动SOJ界面头牌的OJ了。。而且居然VJudge不支持,呵呵。

题目大意:有N支球队,你们是第N支。每个队伍已经有一些分数了,接下来还有M场比赛。每场比赛有两支参赛队伍,赢得队得2分,输的队不得分,平局各得一分。现在你很叼可以操控所有比赛的胜负。问你最后你们队是否能成为第一名(分数严格大于其他所有队分数)?

分析:第一道用满流来解决问题的题。首先明确我们能做两种伎俩。一是我们参与的比赛肯定选我们赢。然后我们不参与的比赛就通过压制分数高的队让他们分数没有我们高,这个trick比较难不是贪心能解决的。首先将分数读进来,并让我队加分:所有参与的比赛*2得到我们队最终得分sum。然后先看看是否已经有队跟你们队的分数sum一样,如果存在则一定是NO了。

如果不存在呢?那么我们就要用最大流来解决,我一开始想的是将你们队作为汇点,然后看看能够得到多少,这样发现并不能与其他队伍比较。最后学习了之后才明白,是将所有队伍与超级汇点连接,关键在于这条边流量限制为sum-1-score[i]。这样一来,则限制了每个队伍的最终得分。那么我们怎么知道这种情况是否存在呢?答案是验证是否是满流,如果是满流的话说明是可以达到这种情况的,输出“YES”,否则输出“NO”。

上代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;

const int MAXN = 1310;
const int MAXM = 2061000;
const int INF = 0x3f3f3f3f;

struct Edge
{
	int to, cap, next;
};

Edge edge[MAXM];
int level[MAXN];
int head[MAXN];
int score[MAXN];
int src, des, cnt;

void addedge( int from, int to, int cap )
{
	edge[cnt].to = to;
	edge[cnt].cap = cap;
	edge[cnt].next = head[from];
	head[from] = cnt++;

	swap( from, to );

	edge[cnt].to = to;
	edge[cnt].cap = 0;
	edge[cnt].next = head[from];
	head[from] = cnt++;

}

int bfs()
{
	memset( level, -1, sizeof level );
	queue<int> q;
	while (!q.empty())
		q.pop();

	level[src] = 0;
	q.push( src );
	
	while (!q.empty())
	{
		int u = q.front();
		q.pop();

		for (int i = head[u]; i != -1; i = edge[i].next)
		{
			int v = edge[i].to;
			if (edge[i].cap > 0 && level[v] == -1)
			{
				level[v] = level[u] + 1;
				q.push( v );
			}
		}
	}
	return level[des] != -1;
}

int dfs( int u, int f )
{
	if (u == des) return f;
	int tem;
	
	for (int i = head[u]; i != -1; i=edge[i].next)
	{
		int v = edge[i].to;
		if (edge[i].cap > 0 && level[v] == level[u] + 1)
		{
			tem = dfs( v, min( f, edge[i].cap ) );
			if (tem > 0)
			{
				edge[i].cap -= tem;
				edge[i^1].cap += tem;
				return tem;
			}
		}
	}
	level[u] = -1;
	return 0;
}

int Dinic()
{
	int ans = 0, tem;
	while (bfs())
	{
		while (tem = dfs( src, INF ))
		{
			ans += tem;
		}
	}
	return ans;
}

int main()
{
	int n, m;
	src = 0;
	des = 1111;
	while (cin >> n >> m)
	{
		memset( head, -1, sizeof head );
		cnt = 0;
		int flow = 0;
		for (int i = 1; i <= n; i++)
		{
			cin >> score[i];
		}

		for (int i = 1; i <= m; i++)
		{
			int a, b;
			cin >> a >> b;
			if (a == n || b == n) score[n] += 2;
			else
			{
				addedge( src, i + 100, 2 );
				addedge( i + 100, a, 2 );
				addedge( i + 100, b, 2 );
				flow += 2;
			}

		}

		int flag = true;
		for (int i = 1; i < n; i++)
		{
			if (score[i] >= score[n])
			{
				flag = false;
				break;
			}
		}
		if (!flag)
		{
			cout << "NO" << endl;
			continue;
		}

		for (int i = 1; i < n; i++)
		{
			addedge( i, des, score[n] - 1-score[i] );
		}

		if (Dinic() == flow) cout << "YES" << endl;
		else cout << "NO" << endl;

	}

	return 0;
}


看来最大流的妙用还只是掌握了皮毛啊。。。继续加油!!!



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值