SGU 326 Perspective(最大流)
Description
Being his advisor, you need to determine whether it's possible for your team to finish first in its division or not.
More formally, the NBA regular season is organized as follows: all teams play some games, in each game one team wins and one team loses. Teams are grouped into divisions, some games are between the teams in the same division, and some are between the teams in different divisions.
Given the current score and the total number of remaining games for each team of your division, and the number of remaining games between each pair of teams in your division, determine if it's possible for your team to score at least as much wins as any other team in your division.
Input
The second line of input contains N integers w1, w2,..., wN, where wi is the total number of games that ith team has won to the moment.
The third line of input contains N integers r1, r2,..., rN, where ri is the total number of remaining games for the ith team (including the games inside the division).
The next N lines contain N integers each. The jth integer in the ith line of those contains aij — the number of games remaining between teams i and j. It is always true that aij=a ji and aii=0, for all iai1+ ai2 +... + aiN ≤ ri.
All the numbers in input are non-negative and don't exceed 10\,000.
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.
题目大意:某小组有n支队伍要比赛,现在每支队伍已经赢了w[i]场,每支队伍还要比r[i]场,每场分同小组竞赛和不同小组竞赛,然后给一个矩阵(小组内竞赛),i行j列为队伍i与队伍j还要比多少场比赛,问队伍1有没有在小组内拿最高分(假设赢一场得一分)的可能性(可以跟其他队伍同分)
思路:首先,队伍1要赢,最好是要1把所有比赛都赢了(包括小组内和小组外),然后其他小组的分都要尽量低,所以其他队伍都要输掉小组外的比赛。那么设小组1能赢max_score场。那么怎么分配其他比赛的获胜方呢?这里就要用到网络流建图。从源点到每支队伍间的比赛连一条边,容量为该竞赛的场数,然后该竞赛再向该比赛的两支队伍连一条容量为无穷大的边(你喜欢容量为场数也可以o(╯□╰)o)。然后,每支队伍(不包括1),连一条容量为max_score - w[i]的边到汇点(不能让这支队伍赢太多啊会超过1的o(╯□╰)o)。如果最大流等于小组内比赛数,那就是YES(分配了所有比赛的结果,还是没人能超过max_score,有可行解),否则输出NO。
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std; const int INF = 0x7fff7fff;
const int MAX = ;
const int MAXN = MAX * MAX;
const int MAXE = * MAXN; struct Dinic {
int head[MAXN], cur[MAXN], dis[MAXN];
int to[MAXE], next[MAXE], cap[MAXE], flow[MAXE];
int n, st, ed, ecnt; void init() {
memset(head, , sizeof(head));
ecnt = ;
} void add_edge(int u, int v, int c) {
to[ecnt] = v; cap[ecnt] = c; flow[ecnt] = ; next[ecnt] = head[u]; head[u] = ecnt++;
to[ecnt] = u; cap[ecnt] = ; flow[ecnt] = ; next[ecnt] = head[v]; head[v] = ecnt++;
} bool bfs() {
memset(dis, , sizeof(dis));
queue<int> que; que.push(st);
dis[st] = ;
while(!que.empty()) {
int u = que.front(); que.pop();
for(int p = head[u]; p; p = next[p]) {
int v = to[p];
if(!dis[v] && cap[p] > flow[p]) {
dis[v] = dis[u] + ;
que.push(v);
if(v == ed) return true;
}
}
}
return dis[ed];
} int dfs(int u, int a) {
if(u == ed || a == ) return a;
int outflow = , f;
for(int &p = cur[u]; p; p = next[p]) {
int v = to[p];
if(dis[u] + == dis[v] && (f = dfs(v, min(a, cap[p] - flow[p]))) > ) {
flow[p] += f;
flow[p ^ ] -= f;
outflow += f;
a -= f;
if(a == ) break;
}
}
return outflow;
} int Maxflow(int ss, int tt, int nn) {
st = ss; ed = tt; n = nn;
int ans = ;
while(bfs()) {
for(int i = ; i <= n; ++i) cur[i] = head[i];
ans += dfs(st, INF);
}
return ans;
}
} G; int r[MAX], w[MAX];
int n; int main() {
scanf("%d", &n);
for(int i = ; i <= n; ++i) scanf("%d", &w[i]);
for(int i = ; i <= n; ++i) scanf("%d", &r[i]);
int max_score = w[] + r[], node_cnt = n, game_cnt = ;
for(int i = ; i <= n; ++i)
if(max_score < w[i]) {puts("NO"); return ;}
G.init();
int ss = ;
for(int i = ; i <= n; ++i) for(int j = ; j <= n; ++j) {
int x; scanf("%d", &x);
if(i == || i >= j || x == ) continue;
game_cnt += x;
G.add_edge(ss, ++node_cnt, x);
G.add_edge(node_cnt, i, INF);
G.add_edge(node_cnt, j, INF);
}
int tt = ++node_cnt;
for(int i = ; i <= n; ++i) G.add_edge(i, tt, max_score - w[i]);
if(G.Maxflow(ss, tt, node_cnt) == game_cnt) puts("YES");
else puts("NO");
}
SGU 326 Perspective(最大流)的更多相关文章
- SGU 326 Perspective ★(网络流经典构图の竞赛问题)
[题意]有n(<=20)只队伍比赛, 队伍i初始得分w[i], 剩余比赛场数r[i](包括与这n只队伍以外的队伍比赛), remain[i][j]表示队伍i与队伍j剩余比赛场数, 没有平局, 问 ...
- sgu 326(经典网络流构图)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=13349 题目大意:有N个球队在同一个赛区,已知他们胜利的场数,还剩 ...
- [转] POJ图论入门
最短路问题此类问题类型不多,变形较少 POJ 2449 Remmarguts' Date(中等)http://acm.pku.edu.cn/JudgeOnline/problem?id=2449题意: ...
- Soj题目分类
-----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...
- 图论常用算法之一 POJ图论题集【转载】
POJ图论分类[转] 一个很不错的图论分类,非常感谢原版的作者!!!在这里分享给大家,爱好图论的ACMer不寂寞了... (很抱歉没有找到此题集整理的原创作者,感谢知情的朋友给个原创链接) POJ:h ...
- 千里积于跬步——流,向量场,和微分方程[转载]
在很多不同的科学领域里面,对于运动或者变化的描述和建模,都具有非常根本性的地位--我个人认为,在计算机视觉里面,这也是非常重要的. 什么是"流"? 在我接触过的各种数学体系中,对于 ...
- SGU 176 【带上下界的有源汇的最小流】
---恢复内容开始--- 题意: 给了n个点,m条有向边. 接下来m行,每条边给起点终点与容量,以及一个标记. 标记为1则该边必须满容量,0表示可以在容量范围内任意流. 求: 从源点1号点到终点n号点 ...
- 【无源汇上下界最大流】SGU 194 Reactor Cooling
题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=194 题目大意: n个点(n<20000!!!不是200!!!RE了无数次) ...
- SGU 176 Flow construction(有源汇上下界最小流)
Description 176. Flow construction time limit per test: 1 sec. memory limit per test: 4096 KB input: ...
随机推荐
- c#(IronPython)调用Python方法
直接一段代码演示 public void StartTCP() { ScriptEngine engine = Python.CreateEngine(); var paths = engine.Ge ...
- nopCommerce电子商务平台 安装教程(图文)
nopCommerce是一个通用的电子商务平台,适合每个商家的需要:它强大的企业和小型企业网站遍布世界各地的公司销售实体和数字商品.nopCommerce是一个透明且结构良好的解决方案,它结合了开源和 ...
- VMware Workstation 安装Vmware tools 是 出现vmware tools unavailable
这个问题是因为虚拟机安装的时候操作系统选择的不对,在Virtual Machine Settings中选择Options,在General中选择正确的操作系统类型 例如Guest operating ...
- MAC系统 输入管理员账户密码 登录不上
mac新系统改密码~管理员 升级10.13.2后,很多不会操作了, 那天把系统管理员设置成了普通管理,就不能打开个别软件了, 贼尴尬~~~ 后来找blog才解决,现在分享下~~ http://www. ...
- ckeditor + ckfinder + oss存储
ckeditor 与 ckfinder 的整合方法 网上有很多,这里我也就不说了. (主要是以前整合的现在忘记咋弄的了0.0) 我这里整合后直接使用js代码 <script type=&quo ...
- Java软件开发者,如何学习大数据?
正常来讲学习大数据之前都要做到以下几点 1.学习基础的编程语言(java,python) 2.掌握入门编程基础(linux操作,数据库操作.git操作) 3.学习大数据里面的各种框架(hadoop.h ...
- requests+mongodb爬取今日头条,多进程
import json import os from urllib.parse import urlencode import pymongo import requests from bs4 imp ...
- C++编译错误杂记
目录 2018年12月23日 error: no matching function for call to ××× 2018年12月10日 error: expected ')' before '* ...
- react--基本用法
1.安装了babel 但是终端执行 babel src --out-dir build命令时说"babel:command is not found" 经百度,找到solution ...
- React Router 4.0 实现路由守卫
在使用 Vue 或者 Angular 的时候,框架提供了路由守卫功能,用来在进入某个路有前进行一些校验工作,如果校验失败,就跳转到 404 或者登陆页面,比如 Vue 中的 beforeEnter 函 ...