whu 1124 Football Coach(最大流,判断满流)
来源:互联网 发布:java的输入流和输出流 编辑:程序博客网 时间:2024/05/20 17:07
Problem 1124 - Football Coach
Time Limit: 2000MS Memory Limit: 65536KB
Total Submit: 239 Accepted: 100 Special Judge: No
Total Submit: 239 Accepted: 100 Special Judge: No
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.
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.
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.
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
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
NO
题意:有n个足球队,剩余m场比赛。给出每个队现有的分数,再给出m场比赛中的队伍。每场比赛,胜出者得2分,败者得0分,或打平时各得一分。你可以操纵全部m场比赛的结果,问最后是否能使队伍n的分数最高。
思路:首先,有队伍n的比赛,都使队伍n赢,累加n能得到的分数,设最后n的分数最多为sum。那么m场比赛前如果有足球队现有的分数超过sum - 1,显然不能使队伍n分数最高,如果不存在,那么就可以构图了。将事件看成点,即将每场比赛看成点,源点向每场比赛连边,容量为2,每场比赛向相应的队伍连边,容量都为2,然后每个队伍向汇点连边,容量为sum - 1 - 该队伍现有的分数。最后如果最大流是满流的,则可行。
AC代码:
#include <iostream>#include <cmath>#include <cstdlib>#include <cstring>#include <cstdio>#include <queue>#include <ctime>#include <vector>#include <algorithm>#define ll long long#define L(rt) (rt<<1)#define R(rt) (rt<<1|1)#define eps 1e-6using namespace std;const int INF = 1e8;const int maxn = 2005;struct Edge{ int u, v, cap, flow, next;}et[maxn * maxn];int low[maxn], cnt[maxn], dis[maxn], pre[maxn], cur[maxn], eh[maxn];int p[maxn];int n, m, s, t, num;void init(){ memset(eh, -1, sizeof(eh)); num = 0;}void add(int u, int v, int cap, int flow){ Edge e = {u, v, cap, flow, eh[u]}; et[num] = e; eh[u] = num++;}void addedge(int u, int v, int cap){ add(u, v, cap, 0); add(v, u, 0, 0);}int isap(int s, int t, int nv){ int u, v, now, flow = 0; memset(low, 0, sizeof(low)); memset(cnt, 0, sizeof(cnt)); memset(dis, 0, sizeof(dis)); for(u = 0; u <= nv; u++) cur[u] = eh[u]; low[s] = INF, cnt[0] = nv, u = s; while(dis[s] < nv) { for(now = cur[u]; now != -1; now = et[now].next) if(et[now].cap - et[now].flow && dis[u] == dis[v = et[now].v] + 1) break; if(now != -1) { cur[u] = pre[v] = now; low[v] = min(low[u], et[now].cap - et[now].flow); u = v; if(u == t) { for(; u != s; u = et[pre[u]].u) { et[pre[u]].flow += low[t]; et[pre[u]^1].flow -= low[t]; } flow += low[t]; low[s] = INF; } } else { if(--cnt[dis[u]] == 0) break; dis[u] = nv, cur[u] = eh[u]; for(now = eh[u]; now != -1; now = et[now].next) if(et[now].cap - et[now].flow && dis[u] > dis[et[now].v] + 1) dis[u] = dis[et[now].v] + 1; cnt[dis[u]]++; if(u != s) u = et[pre[u]].u; } } return flow;}int main(){ int a, b; while(~scanf("%d%d", &n, &m)) { init(); s = 0; t = n + m + 1; for(int i = 1; i <= n; i++) scanf("%d", &p[i]); int sum = p[n], sumflow = 0; for(int i = 1; i <= m; i++) { scanf("%d%d", &a, &b); if(a == n || b == n) sum += 2; else { sumflow += 2; addedge(s, i, 2); addedge(i, a + m, 2); addedge(i, b + m, 2); } } bool flag = true; for(int i = 1; i <= n; i++) if(p[i] >= sum) { flag = false; break; } if(!flag) { printf("NO\n"); continue; } for(int i = 1; i < n; i++) addedge(i + m, t, sum - 1 - p[i]); if(sumflow == isap(s, t, t + 1)) printf("YES\n"); else printf("NO\n"); } return 0;}
0 0
- whu 1124 Football Coach(最大流,判断满流)
- WHU 1124 Football Coach(最大流)
- WHU 1124 Football Coach(最大流,巧妙构图)
- WOJ 124 Football Coach(网络流)
- whu 1124 最大流和sgu 326 思路一样
- WOJ1124-Football Coach
- 解题报告 之 WHU1124 Football Coach
- 三分--Football Goal(面积最大)
- hdu 3572 最大流判断满流
- 【ZOJ】2332 Gems 最大流——判断满流
- hdu3572 任务分配/最大流判断满流
- HDU 2883 kebab【最大流】(判断是否满流)
- HDU3572Task Schedule(任务分配/最大流判断满流)
- Task Schedule 【最大流 判断是否满流】
- HDU3572——Task Schedule (最大流判断满流)
- [HDOJ 4924] Football Manager [枚举+费用流]
- UVa 563 Crimewave ( 用最大流判断,拆点)
- hdu4862Jump【最大费用最大流,判断是否满流】2014多校联合
- LeetCode之Merge Sorted Array
- Linux添加/删除用户和用户组
- LeetCode || Linked List Cycle 1&2
- 哈希函数
- CSS学习三
- whu 1124 Football Coach(最大流,判断满流)
- application开发(网上总结)
- Python3.2官方文档教程---元组与序列
- LeetCode之Search Insert Position
- poj3181-完全背包+高精度
- 算法:链表的归并排序
- ActionBarActivity ActionBar Fragment
- 3.要学习的东西不仅仅是技术本身
- C++ 新手游戏开发之细节问题(1)