sgu 326 Perspective
来源:互联网 发布:铜陵网络电视台 编辑:程序博客网 时间:2024/04/28 00:54
题意:一个赛区有N个球队,1号球队是自己的,每个球队有已经获得的分数,剩余的比赛场数,赛区内球队之间的比赛场数都为已知。
为了获得第一,假设1号球队剩余的比赛场数都胜利,更新score[1],赛区内其他队伍跨赛区的比赛都失败。
接下来建图,从S到每一个球队连接一条容量为score[1] - score[i]的值,若球队i跟j存在比赛k场,连接i,p,容量为k,连接j,p容量为k,连接p,t容量为k
若所以P到t的容量之和>最大流,则输出NO,表示比赛没有打完,所有的球队分数都与1号球队相同了,反正,输出YES
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int INF=1000000000;
const int N=5005;
struct Node
{
int v,cap,flow,next;
};
Node edges[N];
int n,m,s,t,head[N],e;
int num[N],h[N],curedge[N],pre[N];
void add(int u,int v,int cap)
{
edges[e].v=v;
edges[e].cap=cap;
edges[e].flow=0;
edges[e].next=head[u];
head[u]=e++;
}
void Add(int u,int v,int cap)
{
add(u,v,cap);//正向边初始化为cap
add(v,u,0);//反向边初始化为0
}
int Maxflow(int s,int t,int n)
{
int ans=0,i,k,x,d,u;
memset(num,0,sizeof(num));
memset(h,0,sizeof(h));
for(i=0;i<=n;i++) curedge[i]=head[i];
num[n]=n;u=s;
while(h[u]<n)//每一个节点到汇点的距离小于等于n-1
{
if(u==t)
{
d=INF+1;
//获得最短路径上的最小流和流出最小流的节点
for(i=s;i!=t;i=edges[curedge[i]].v) if(d>edges[curedge[i]].cap)
k=i,d=edges[curedge[i]].cap;
//更新图
for(i=s;i!=t;i=edges[curedge[i]].v)
{
x=curedge[i];
edges[x].cap-=d;
edges[x].flow+=d;
edges[x^1].cap+=d;
edges[x^1].flow-=d;
}
ans+=d;u=k;
}
//找到一条允许的边,即最短路径上的边,并将该节点的当前边记录下来。
for(i=curedge[u];i!=-1;i=edges[i].next) if(edges[i].cap>0&&h[u]==h[edges[i].v]+1)
break;
if(i!=-1)
{
curedge[u]=i;
pre[edges[i].v]=u;
u=edges[i].v;
}
else //更新u节点到汇点的最短路
{
//某一种路径出现断流
if(--num[h[u]]==0) break;
//更新u节点的当前边和最短路
curedge[u]=head[u];
for(x=n,i=head[u];i!=-1;i=edges[i].next) if(edges[i].cap>0&&h[edges[i].v]<x)
x=h[edges[i].v];
h[u]=x+1;num[h[u]]++;
if(u!=s) u=pre[u];
}
}
return ans;
}
int score[50];
int r[50];
int map[50][50];
int main()
{
while(scanf("%d",&n)!=EOF)
{
e = 0;
memset(head,-1,sizeof(head));
memset(r,0,sizeof(r));
memset(score,0,sizeof(score));
memset(map,0,sizeof(map));
for(int i = 1;i<=n;i++)
{
scanf("%d",&score[i]);
}
for(int i = 1;i<=n;i++)
{
scanf("%d",&r[i]);
}
for(int i = 1;i<=n;i++)
for(int j = 1;j<=n;j++)
{
scanf("%d",&map[i][j]);
}
score[1]+=r[1];
s = 0;
t = 1000;
int ans = 1;
for(int i = 2;i<=n;i++)
{
if(score[i]>score[1])
{
ans = 0;
break;
}
Add(s,i-1,score[1]-score[i]);
}
int cnt = 1,sum = 0;
if(!ans)
{
printf("NO\n");
}
else
{
for(int i = 2;i<=n;i++)
for(int j = i+1;j<=n;j++)
{
if(map[i][j])
{
Add(i-1,n-1+cnt,map[i][j]);
Add(j-1,n-1+cnt,map[i][j]);
Add(n-1+cnt,1000,map[i][j]);
sum += map[i][j];
cnt++;
}
}
if(Maxflow(s,t,n+cnt+1)==sum)
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}
- SGU 326 Perspective
- sgu 326 Perspective
- SGU-326-Perspective
- SGU 326 Perspective
- SGU 326 -- Perspective
- sgu 326 Perspective(最大流)
- sgu 326——Perspective
- SGU 326 Perspective最大流
- SGU 326 Perspective ( 网络流 )
- SGU 326 Perspective(网络流)
- SGU 326 Perspective (网络流)
- SGU 326 Perspective【最大流 竞赛图】
- SGU 326 Perspective (网络流)
- SGU 326. Perspective //MAXFLOW
- SGU 326 - Perspective(网络流‘最大流)
- SGU 326. Perspective (最大流)
- sgu Perspective 网络流 竞赛图
- sgu 326. Perspective (最大流)
- 在visual studio 2010中调用ffmpeg
- request方法大全
- jdk+weblogic+myeclipse+flex环境配置
- 网址
- Ubuntu11.10下为Eclipse安装svn插件[验证OK]
- sgu 326 Perspective
- c语言指针详解(一)
- js webbrowser C#
- JAVA基础之数组,List,MAP。排序,最值
- 企业级软件演进和J2EE概述
- vi编辑器
- 我的智能家庭规划
- window下(或Ubuntu下)Sublime Text 2.01注册码license key
- 自制Runtime:虚拟执行环境设计