一场比赛在规定时间内比完 胜者3分败者0分,加时赛比完胜者2分败者1分
然后联赛是单循环赛(任何两只队伍比一次),给出了上赛季每只队伍的积分,问你这个积分合不合理,如果合理则要输出方案。
首先我们发现一场比赛的积分固定,然后3分无论怎么分配都能对应一种胜负情况,因此用最大流
将每场比赛和每一只队伍分别抽象成点(比赛点: 1 -至2*n*(n-1) 队伍点 2*n*(n-1)+1 至2*n*(n-1)+n )
源点和每场比赛连 容量3
每场比赛和对应的两只队伍连,容量分别是3
然后每一只队伍和汇点连,容量是这只队伍上赛季积分。
然后最大流判断满流,如果不是满流则不合理
否则根据边上残余网络的容量输出方案。
1736. Chinese Hockey
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
Sergey and Denis closely followed the Chinese Football Championship, which has just come to an end. They supported the
Katraps and
Komolotiv teams, but, unfortunately, these teams tied for last place in the championship. Sergey was so disappointed that he suggested Denis that they change to hockey fans.
There are
n teams competing in the Chinese Ice Hockey Championship. During the season, each team must play with each other team exactly one game. If a team wins in the regulation time, it gets 3 points and the losing team gets 0 points. If the regulation time is ended in a draw, then the overtime is played. The team that wins in the overtime gets 2 points and the team that loses gets 1 point. A game can't end in a draw in ice hockey.
Denis wants to determine which team he will support. In order to make the choice, he has found a table on the Web in which it is shown for each team how many points it scored in the last year's season. Sergey suspects that there is a mistake in this table because no all-play-all tournament could end with such results. Is Sergey right?
Input
The first line contains the integer
n (2 ≤
n ≤ 200). The second line contains
n space-separated non-negative integers; they are the scores of the teams in the previous championship. The scores are given in the non-increasing order. The sum of all the scores is
3
n(
n–1)/2
. None of the teams scored more than
3(
n–1)
points.
Output
If Sergey is right and there is a mistake in the table, output “INCORRECT” in the only line. Otherwise, in the first line output “CORRECT” and in the following
n(
n–1)/2
lines output the results of the games. Each result must have the form “
i ? j
”, where
i and
j are the numbers of the teams that played the game and
?
can be
<
,
<=
,
>=
, or
>
, which means that the first team lost in the regulation time, lost in the overtime, won in the overtime, and won in the regulation time, respectively. The teams are numbered from 1 to
n in the order in which they are given in the input.
Samples
input | output |
---|---|
4 8 7 2 1 | CORRECT 2 <= 1 3 >= 4 1 > 3 4 < 2 1 > 4 2 > 3 |
4 8 8 1 1 | INCORRECT |
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 40000
#define INF 0xFFFFFF
struct edge
{
int to,c,next;
};
edge e[999999];
int que[MAXN*100];
int dis[MAXN],pre[MAXN];
int head[MAXN],head2[MAXN];
int st,ed,maxflow;
int en,n;
void add(int a,int b,int c)
{
e[en].to=b;
e[en].c=c;
e[en].next=head[a];
head[a]=en++;
e[en].to=a;
e[en].c=0;
e[en].next=head[b];
head[b]=en++;
}
bool bfs()
{
memset(dis,-1,sizeof(dis));
que[0]=st,dis[st]=1;
int t=1,f=0;
while(f<t)
{
int j=que[f++];
for(int k=head[j];k!=-1;k=e[k].next)
{
int i=e[k].to;
if(dis[i]==-1 && e[k].c)
{
que[t++]=i;
dis[i]=dis[j]+1;
if(i==ed) return true;
}
}
}
return false;
}
int update()
{
int p,flow=INF;
for (int i=pre[ed];i!=-1;i=pre[i])
if(e[head2[i]].c<flow) p=i,flow=e[head2[i]].c;
for (int i=pre[ed];i!=-1;i=pre[i])
e[head2[i]].c-=flow,e[head2[i]^1].c+=flow;
maxflow+=flow;
return p;
}
void dfs()
{
memset(pre,-1,sizeof(pre));
memcpy(head2,head,sizeof(head2));
for(int i=st,j;i!=-1;)
{
int flag=false;
for(int k=head[i];k!=-1;k=e[k].next)
if(e[k].c && (dis[j=e[k].to]==dis[i]+1) )
{
pre[j]=i;
head2[i]=k;
i=j;
flag=true;
if(i==ed)
i=update();
if(flag)
break;
}
if (!flag) dis[i]=-1,i=pre[i];
}
}
int dinic()
{
maxflow=0;
while(bfs())
dfs();
return maxflow;
}
int main()
{
while(~scanf("%d",&n))
{
memset(head,-1,sizeof(head));en=0;
int total=n*(n-1)/2+n+1,bas=n*(n-1)/2,cnt=1;
st=0,ed=total;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
{
add(cnt,bas+i,3);
add(cnt,bas+j,3);
cnt++;
}
for(int i=1;i<=n*(n-1)/2;i++) add(st,i,3);
int sum=0;bool ok=1;
for(int i=n*(n-1)/2+1;i<=n*(n-1)/2+n;i++)
{
int tmp;
scanf("%d",&tmp);
sum+=tmp;
if(tmp>3*(n-1)) ok=0;
add(i,ed,tmp);
}
dinic();
if(!ok||sum!=3*n*(n-1)/2||maxflow!=3*n*(n-1)/2)
printf("INCORRECT\n");
else
{
cnt=0;
printf("CORRECT\n");
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
{
int si=3-e[cnt].c;
int sj=3-e[cnt+2].c;
cnt+=4;
if(si==3)
printf("%d > %d\n",i,j);
else if(si==2)
printf("%d >= %d\n",i,j);
else if(si==0)
printf("%d < %d\n",i,j);
else if(si==1)
printf("%d <= %d\n",i,j);
}
}
}
return 0;
}