标签:
Description
Input
Output
YES" (without quotes) if it‘s possible for the team 1 to score at least as much wins as any other team of its division, and "
NO" (without quotes) otherwise.
Sample Input
sample input |
sample output |
3 1 2 2 1 1 1 0 0 0 0 0 0 0 0 0 |
YES |
sample input |
sample output |
3 1 2 2 1 1 1 0 0 0 0 0 1 0 1 0 |
NO |
题目大意:本小组内有N支队伍,你是team1。现在每个队已经有了score[i]的分,并且总共还剩下remain[i]场比赛(包括组内比赛和跨组比赛)。然后给你一个N*N的矩阵match表示组内剩余比赛,match[i][j]表示i与j队伍还剩多少场比赛,保证match[i][j]==match[j][i],并且match[i][i]==0(忽然想起了前面那道坑题不保证这一点,妈蛋)。每场比赛不存在平局,赢的得1分,输的得2分。然后问你你们组是否有可能得小组第一(分数大于等于其他所有组内队伍)?
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int MAXN = 610;
const int MAXM = 361000;
const int INF = 0x3f3f3f3f;
struct Edge
{
int to, cap, next;
};
Edge edge[MAXM];
int level[MAXN];
int head[MAXN];
int score[MAXN];
int remain[MAXN];
int match[MAXN][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;
src = 0;
des = 605;
while (cin >> n)
{
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 <= n; i++)
{
cin >> remain[i];
}
//每队还剩多少场比赛
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
{
cin >> match[i][j];
remain[i] -= match[i][j];
}
//算出每个队伍有几场外部比赛
int g = 21;
for (int i = 1; i <= n; i++)
{
for (int j = i + 1; j <= n; j++)
{
if (match[i][j])
{
if (i == 1)
{
score[1] += match[i][j];
}
else
{
addedge( src, g, match[i][j] );
addedge( g, i, match[i][j] );
addedge( g, j, match[i][j] );
g++;
flow += match[i][j];
}
}
}
}
int flag = true;
for (int i = 1; i <= n; i++)
{
if(i==1)
score[i] += remain[i];
if (score[i] > score[1] && i > 1)
{
flag = false;
break;
}
}//更新外部比赛后的最高得分
if (!flag)
{
cout << "NO" << endl;
continue;
}
for (int i = 2; i <= n; i++)
{
addedge( i, des, score[1] - score[i] );
}
if (Dinic() == flow) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}标签:
原文地址:http://blog.csdn.net/maxichu/article/details/45167687