SGU326_Perspective
NBA打比赛。所有的比赛被分为多个团队。有的比赛是团内的,有的是与团外的队伍打的。
给出团内每个队伍已得分,以及总共有多少场比赛,还有团内所有队伍之间有多少场比赛?
问1队是否可能是分数最高的一个队伍。(题目没说是否唯一最高,枚举题意得知不是唯一)
又是一个竞赛图的最大流。团内的比赛,如果有一个队伍是1队,那么安排结果1队胜利,另一队伍失败。
对于所有与外团的比赛,与1队有关的都胜利,否则失败。
接下来建图,我们做完前面的工作后,分别统计所有的队伍得分,1队分数减去x队的分数就是x队在所有的团内赛中最多能够胜利的场数。
模型就出来了,源点->队伍->比赛->汇点,最终我们只要判断所有比赛的出边是否满流,即所有的比赛能否安排得下即可。
召唤代码君:
#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 5550
#define maxm 55550
using namespace std; int next[maxm],to[maxm],c[maxm],first[maxn],edge=-;
int score[maxn],test[maxn],tag[maxn],TAG=;
bool can[maxn];
int a[][],node=-,d[maxn];
int Q[maxn],bot,top;
int alltest=,ans,n,m,s,t; int addnode()
{
first[++node]=-;
return node;
} void addedge(int U,int V,int W)
{
edge++;
to[edge]=V,c[edge]=W,next[edge]=first[U],first[U]=edge;
edge++;
to[edge]=U,c[edge]=,next[edge]=first[V],first[V]=edge;
} bool bfs()
{
Q[bot=top=]=t,d[t]=,tag[t]=++TAG,can[t]=false;
while (bot<=top)
{
int cur=Q[bot++];
for (int i=first[cur]; i!=-; i=next[i])
if (c[i^]> && tag[to[i]]!=TAG)
{
tag[to[i]]=TAG,can[to[i]]=false;
d[to[i]]=d[cur]+,Q[++top]=to[i];
if (to[i]==s) return true;
}
}
return false;
} int dfs(int cur,int num)
{
if (cur==t) return num;
int tmp=num,k;
for (int i=first[cur]; i!=-; i=next[i])
if (c[i]> && tag[to[i]]==TAG && !can[to[i]] && d[to[i]]==d[cur]-)
{
k=dfs(to[i],min(num,c[i]));
if (k) num-=k,c[i]-=k,c[i^]+=k;
if (num==) break;
}
if (num) can[cur]=true;
return tmp-num;
} bool _input()
{
scanf("%d",&n);
s=addnode();
for (int i=; i<=n; i++) t=addnode();
t=addnode();
for (int i=; i<=n; i++) scanf("%d",&score[i]);
for (int i=; i<=n; i++) scanf("%d",&test[i]);
for (int i=; i<=n; i++)
for (int j=; j<=n; j++)
{
scanf("%d",&a[i][j]);
if (!a[i][j] || i>=j) continue;
test[i]-=a[i][j],test[j]-=a[i][j];
if (i==) score[]+=a[i][j];
else
{
alltest+=a[i][j];
int tmp=addnode();
addedge(i,tmp,a[i][j]);
addedge(j,tmp,a[i][j]);
addedge(tmp,t,a[i][j]);
}
}
score[]+=test[];
for (int i=; i<=n; i++)
{
if (score[i]>score[]) return false;
addedge(s,i,score[]-score[i]);
}
int ans=;
while (bfs()) ans+=dfs(s,maxn);
return ans==alltest;
} int main()
{
if (_input()) puts("YES");
else puts("NO");
return ;
}
SGU326_Perspective的更多相关文章
随机推荐
- PHP Rabbitmq 报错Broken pipe
fwrite(): send of 13 bytes failed with errno=32 Broken pipe fwrite(): send of 21 bytes failed with e ...
- pycharm导入路径问题
博主在导入自定义模块式出现模块下有红色波浪线,如下: 例如from conf import setting 导入时会从当前目录下找找到youkuClient就不会再往下找了,所以引入模块的路径不能夸路 ...
- Direct2D处理几何图形之间的碰撞检测(下)
转载请注明出处:http://www.cnblogs.com/Ray1024 一.概述 上一篇文章中我们介绍了几何图形与点的碰撞检测.几何图形与点的位置关系比较简单:点在几何图形内.点在几何图形外.点 ...
- sql server sql查询数据库的表,字段,主键,自增,字段类型等信息
1.查询数据表的属性(名称.说明.是否主键.数据类型.是否自增) SELECT t1.name columnName,case when t4.id is null then 'false' else ...
- 引用“kernel32”读写ini配置文件
引用"kernel32"读写ini配置文件 unity ini kernel32 配置文件 引用"kernel32"读写ini配置文件 OverView ke ...
- python3安装与环境配置和pip的基本使用
本文环境 系统: Windows10 Python版本: 3.6 安装 python安装包下载 可以选择安装版和解压版 安装版一键安装, 安装过程注意选择安装位置, xx To Path选项(勾选), ...
- 【Python学习笔记】正则表达式
Ref:https://deerchao.net/tutorials/regex/regex.htm#greedyandlazy 1. 常用元字符 2.字符转义 查找元字符本身时,需要使用\来取消这些 ...
- 控制台报错: SCRIPT1006: Expected ')'
今天做网站的时候,jsp页面取一个值死活取不出来. <script> if(${not empty requestScope.article.articleId}){ alert(${re ...
- python虚拟环境管理之virtualenv,virtualenvwrapper,pipenv,conda
虚拟环境的作用 使python环境拥有独立的包,避免污染原本的python环境.为不同的项目创建不同的环境可以避免安装的库过于庞大和相互干扰. 例如你想在同一台机器上开发用python2和python ...
- Redis源码阅读(四)集群-请求分配
Redis源码阅读(四)集群-请求分配 集群搭建好之后,用户发送的命令请求可以被分配到不同的节点去处理.那Redis对命令请求分配的依据是什么?如果节点数量有变动,命令又是如何重新分配的,重分配的过程 ...