ACM Computer Factory(dinic)
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 5596 | Accepted: 1922 | Special Judge |
Description
As you know, all the computers used for ACM contests must be identical, so the participants compete on equal terms. That is why all these computers are historically produced at the same factory.
Every ACM computer consists of P parts. When all these parts are present, the computer is ready and can be shipped to one of the numerous ACM contests.
Computer manufacturing is fully automated by using N various machines. Each machine removes some parts from a half-finished computer and adds some new parts (removing of parts is sometimes necessary as the parts cannot be added to a computer in arbitrary order). Each machine is described by its performance (measured in computers per hour), input and output specification.
Input specification describes which parts must be present in a half-finished computer for the machine to be able to operate on it. The specification is a set of P numbers 0, 1 or 2 (one number for each part), where 0 means that corresponding part must not be present, 1 — the part is required, 2 — presence of the part doesn't matter.
Output specification describes the result of the operation, and is a set of P numbers 0 or 1, where 0 means that the part is absent, 1 — the part is present.
The machines are connected by very fast production lines so that delivery time is negligibly small compared to production time.
After many years of operation the overall performance of the ACM Computer Factory became insufficient for satisfying the growing contest needs. That is why ACM directorate decided to upgrade the factory.
As different machines were installed in different time periods, they were often not optimally connected to the existing factory machines. It was noted that the easiest way to upgrade the factory is to rearrange production lines. ACM directorate decided to entrust you with solving this problem.
Input
Input file contains integers P N, then N descriptions of the machines. The description of ith machine is represented as by 2 P + 1 integers Qi Si,1 Si,2...Si,P Di,1 Di,2...Di,P, where Qi specifies performance, Si,j— input specification for part j, Di,k — output specification for part k.
Constraints
1 ≤ P ≤ 10, 1 ≤ N ≤ 50, 1 ≤ Qi ≤ 10000
Output
Output the maximum possible overall performance, then M — number of connections that must be made, then M descriptions of the connections. Each connection between machines A and B must be described by three positive numbers A B W, where W is the number of computers delivered from A to B per hour.
If several solutions exist, output any of them.
Sample Input
Sample input 1
3 4
15 0 0 0 0 1 0
10 0 0 0 0 1 1
30 0 1 2 1 1 1
3 0 2 1 1 1 1
Sample input 2
3 5
5 0 0 0 0 1 0
100 0 1 0 1 0 1
3 0 1 0 1 1 0
1 1 0 1 1 1 0
300 1 1 2 1 1 1
Sample input 3
2 2
100 0 0 1 0
200 0 1 1 1
Sample Output
Sample output 1
25 2
1 3 15
2 3 10
Sample output 2
4 5
1 3 3
3 5 3
1 2 1
2 4 1
4 5 1
Sample output 3
0 0
Hint
Source
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
const int M = , inf = 0x3f3f3f3f ;
struct edge
{
int u , v , timeu ;
int w ;
}e[M * M * ]; struct node
{
int input[] , output[] ;
int w ;
}o[M]; int p , n ;
int src , des ;
int dis[M] ;
int head[M * M * ] ;
int cnt , app ;
struct ABW
{
int a , b , w ;
}step[M * M * ]; bool bfs ()
{
queue <int> q ;
while (!q.empty ())
q.pop () ;
memset (dis , - , sizeof(dis)) ;
dis[src] = ;
q.push (src) ;
while (!q.empty ()) {
int u = q.front () ;
q.pop () ;
for (int i = head[u] ; i != - ; i = e[i].timeu) {
int v = e[i].v ;
if (dis[v] == - && e[i].w > ) {
dis[v] = dis[u] + ;
q.push (v) ;
}
}
}
if (dis[des] > )
return true ;
return false ;
} int dfs (int u , int low)
{
int a = ;
if (u == des)
return low ;
for (int i = head[u] ; i != - ; i = e[i].timeu) {
int v = e[i].v ;
if (e[i].w > && dis[v] == dis[u] + && (a = dfs (v , min (low , e[i].w)))) {
e[i].w -= a ;
if (e[i].u != src && e[i].v != des) {
step[app].a = e[i].u ; step[app].b = e[i].v ; step[app].w = a ;
app++ ;
}
e[i^].w += a ;
return a ;
}
}
dis[u] = - ;
return ;
} void dinic ()
{
int ans = , res = ;
app = ;
while (bfs ()) {
while () {
if (ans = dfs (src , inf))
res += ans ;
else
break ;
}
}
printf ("%d %d\n" , res , app) ;
for (int i = app - ; i >= ; i--)
printf ("%d %d %d\n" , step[i].a + , step[i].b + , step[i].w) ;
} void addedge (int u , int v)
{
e[cnt].u = u ; e[cnt].v = v ; e[cnt].w = o[u].w == - ? o[v].w : o[u].w ; e[cnt].timeu = head[u] ;
head[u] = cnt++ ;
e[cnt].u = v ; e[cnt].v = u ; e[cnt].w = ; e[cnt].timeu = head[v] ;
head[v] = cnt++ ;
} void binary (int s , int l , int r)
{
if (l == r) {
if (s != l && l != n) {
int i ;
for (i = ; i < p ; i++) {
if (o[l].input[i] != && o[s].output[i] != o[l].input[i])
break ;
}
if (i == p) {
addedge (s , l) ;
}
}
return ;
}
int mid = l + r >> ;
binary (s , l , mid) ;
binary (s , mid + , r) ;
} int main ()
{
// freopen ("a.txt" , "r" , stdin) ;
while (~ scanf ("%d%d" , &p , &n)) {
for (int i = ; i < n ; i++) {
scanf ("%d" , &o[i].w) ;
for (int j = ; j < p ; j++) {
scanf ("%d" , &o[i].input[j]) ;
}
for (int j = ; j < p ; j++) {
scanf ("%d" , &o[i].output[j]) ;
}
}
for (int i = ; i < p ; i++) {
o[n].input[i] = o[n].output[i] = ;//源点
o[n + ].input[i] = o[n + ].output[i] = ;//汇点
}
o[n].w = - , o[n + ].w = - ;
src = n , des = n + ; n += ;
cnt = ;
memset (head , - , sizeof(head)) ;
for (int i = ; i < n - ; i++) {
binary(i , , n) ;
}
/* for (int i = 0 ; i < cnt ; i++) {
if (i % 2 == 0)
printf ("%d-->%d === %d , time: %d\n" , e[i].u , e[i].v , e[i].w , e[i].timeu) ;
}
puts ("") ; */
dinic () ;
}
return ;
}
ACM Computer Factory(dinic)的更多相关文章
- POJ-3436:ACM Computer Factory (Dinic最大流)
题目链接:http://poj.org/problem?id=3436 解题心得: 题目真的是超级复杂,但解出来就是一个网络流,建图稍显复杂.其实提炼出来就是一个工厂n个加工机器,每个机器有一个效率w ...
- POJ 3436 ACM Computer Factory (网络流,最大流)
POJ 3436 ACM Computer Factory (网络流,最大流) Description As you know, all the computers used for ACM cont ...
- POJ3436 ACM Computer Factory(最大流/Dinic)题解
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8944 Accepted: 3 ...
- POJ3436:ACM Computer Factory(最大流)
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9963 Accepted: 3 ...
- POJ-3436 ACM Computer Factory(网络流EK)
As you know, all the computers used for ACM contests must be identical, so the participants compete ...
- POJ - 3436 ACM Computer Factory(最大流)
https://vjudge.net/problem/POJ-3436 题目描述: 正如你所知道的,ACM 竞赛中所有竞赛队伍使用的计算机必须是相同的,以保证参赛者在公平的环境下竞争.这就是所有这些 ...
- POJ 3436 ACM Computer Factory(最大流+路径输出)
http://poj.org/problem?id=3436 题意: 每台计算机包含P个部件,当所有这些部件都准备齐全后,计算机就组装完成了.计算机的生产过程通过N台不同的机器来完成,每台机器用它的性 ...
- POJ 3436:ACM Computer Factory(最大流记录路径)
http://poj.org/problem?id=3436 题意:题意很难懂.给出P N.接下来N行代表N个机器,每一行有2*P+1个数字 第一个数代表容量,第2~P+1个数代表输入,第P+2到2* ...
- ACM Computer Factory - poj 3436 (最大流)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5949 Accepted: 2053 Special Judge ...
随机推荐
- WP & Win10开发:实现ListView下拉加载的两种方法
1.通过ListView控件的ContainerContentChanging方法.该方法在列表项被实例化时触发,在列表项最后一个项目实例化的时候触发刷新数据逻辑就可以实现下拉加载了. 代码如下:// ...
- Android 中 appcompat_v7与各类资源报错问题
最近导一个项目进eclipse弄了一天都弄不好,先总结如下 首先按照网上其他同志的导入sdk/extras下的appcompat_v7项目.然后 发现 我们这里已经更新到6.0了,也就是说,我们报错的 ...
- EF保存平面数据到SqlServer
前言 公司开展一个项目,需要根据客户手机定位获取周围内的精准广告,具体是管理员在地图上绘制多边形的广告范围,落在范围内的客户就看到此广告.下面将我的实现方法简单叙述一下,以供有相同需求的朋友参考. E ...
- C++成员权限控制(总结)
1) 前言 在我学习C++的过程中,类中成员的权限控制一直是比较头疼的一个点,一会public,一会又private,还有protected,再加点继承,而且又有公有继承.私有继承,保护继承,所以感觉 ...
- excel导入数据库
日常工作中,感觉一些基础知识需要做下笔记,可能是刚毕业的缘故吧,还保持着做笔记的习惯,但根据以往经验,纸质笔记最多保持一年,过后想找已是难过登天.电子版笔记感觉很不错,尤其是发布到网络中.笔记内容是本 ...
- 2、面向对象以及winform的简单运用(面向对象的四大基本特性)
面向对象的四大基本特性 面向对象的核心概念就是封装.抽象.继承.多态这四大基本特性,在这里先解释一下它们的定义: 封装:是一种隐藏信息的特性.找到变化并且把它封装起来,你就可以在不影响其它部分的情况下 ...
- MVC上传文件示例
[HttpPost] public void SaveFile(FormCollection form) { var c = Request.Files.Count; ]; } @using (Htm ...
- Linq 分页不可缺少的两个方法
//LINQ分页的方法 //1.获取总页数 public int GetPageCount(int pageSize)//pageSize是每页的行数 { //先查出总共有多少行 int rowCou ...
- linux 通过哪个命令可以查看某个服务及其端口、进程号
netstat/lsof netstat命令用于显示与IP.TCP.UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况 -a 显示一个所有的有效连接信息列表(包括已建立的连接,也 ...
- Java异常分类
一.基本概念 看java的异常结构图 Throwable是所有异常的根,java.lang.ThrowableError是错误,java.lang.ErrorException是异常,java.lan ...