ACM Computer Factory
ACM Computer Factory
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6104 Accepted: 2113 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
Bold texts appearing in the sample sections are informative and do not form part of the actual data.
Source
Northeastern Europe 2005, Far-Eastern Subregion
题意不好懂啊,看了许多的博客,才渐渐的理解题意了,但大多数的博客都需要拆点,但总感觉不需要,就写了一个简单的Dinic,就AC,是不是数据水啊.
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define PI acos(-1.0)
#define MMM 0x3f3f3f3f
#define RR freopen("input.txt","r",stdin)
#define WW freopen("output.txt","w",stdout)
const int INF = 0x3f3f3f3f;
struct node
{
int peed;
int in[15];
int out[15];
} Point[55];
int n,m;
int s,t;
int Map[55][55];
int Flow[55][55];
bool vis[55];
bool sign[55][55];
bool BFS()
{
memset(vis,false,sizeof(vis));
memset(sign,false,sizeof(sign));
queue<int>Q;
Q.push(s);
vis[s]=true;
while(!Q.empty())
{
int u=Q.front();
Q.pop();
for(int i=0;i<=t;i++)
{
if(!vis[i]&&Map[u][i])
{
sign[u][i]=true;
vis[i]=true;
Q.push(i);
}
}
}
return vis[t];
}
int DFS(int star,int num)
{
if(star==t||num==0)
{
return num;
}
int s=0;
int ant;
for(int i=0;i<=t;i++)
{
if(sign[star][i]&&(ant=DFS(i,min(Map[star][i],num)))>0)
{
Map[star][i]-=ant;
Map[i][star]+=ant;
Flow[star][i]+=ant;
Flow[i][star]-=ant;
num-=ant;
s+=ant;
if(num==0)
{
break;
}
}
}
return s;
}
int Dinic()
{
memset(Flow,0,sizeof(Flow));
int sum=0;
while(BFS())
{
sum+=DFS(0,INF);
}
return sum;
}
int main()
{
while(~scanf("%d %d",&m,&n))
{
s=0;
t=n+1;
memset(Map,0,sizeof(Map));
for(int i=1; i<=n; i++)
{
scanf("%d",&Point[i].peed);
for(int j=1; j<=m; j++)
{
scanf("%d",&Point[i].in[j]);
}
for(int j=1; j<=m; j++)
{
scanf("%d",&Point[i].out[j]);
}
}
bool flag;
for(int i=1;i<=n;i++)
{
flag=false;
for(int j=1;j<=m;j++)
{
if(Point[i].in[j]==1)
{
flag=true;
break;
}
}
if(!flag)
{
Map[s][i]=Point[i].peed;
}
flag=false;
for(int j=1;j<=m;j++)
{
if(Point[i].out[j]!=1)
{
flag=true;
break;
}
}
if(!flag)
{
Map[i][t]=Point[i].peed;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i!=j)
{
flag=false;
for(int k=1;k<=m;k++)
{
if(Point[i].out[k]!=Point[j].in[k]&&Point[j].in[k]!=2)
{
flag=true;
break;
}
}
if(!flag)
{
Map[i][j]=min(Point[i].peed,Point[j].peed);
}
}
}
}
int sum=Dinic();
int num=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(Flow[i][j]>0)
{
num++;
}
}
}
cout<<sum<<" "<<num<<endl;
for(int i =1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(Flow[i][j]>0)
{
cout<<i<<" "<<j<<" "<<Flow[i][j]<<endl;
}
}
}
}
return 0;
}
ACM Computer Factory的更多相关文章
- POJ 3464 ACM Computer Factory
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4829 Accepted: 1641 ...
- ACM Computer Factory(dinic)
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5596 Accepted: 1 ...
- POJ3436 ACM Computer Factory 【最大流】
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5412 Accepted: 1 ...
- 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 (网络流,最大流)
POJ 3436 ACM Computer Factory (网络流,最大流) Description As you know, all the computers used for ACM cont ...
- poj3436 ACM Computer Factory, 最大流,输出路径
POJ 3436 ACM Computer Factory 电脑公司生产电脑有N个机器.每一个机器单位时间产量为Qi. 电脑由P个部件组成,每一个机器工作时仅仅能把有某些部件的半成品电脑(或什么都没有 ...
- 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 ...
- ACM Computer Factory - poj 3436 (最大流)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5949 Accepted: 2053 Special Judge ...
随机推荐
- SQL 数据库 连接查询 变量、if else、while
一.连接查询:通过连接运算符可以实现多个表查询. 连接是关系数据库模型的主要特点,也是它区别于其它类型数据库管理系统的一个标志. 常用的两个链接运算符: 1.join on(左右连接) 2.uni ...
- Java初学--无限循环
利用for循环和while循环分别做到,从键盘读取任意数,输入0自动跳出无限循环,并判断有几个正数几个负数. 1.for循环的无限循环: import java.util.Scanner;//引用Sc ...
- codevs 1204 寻找子串位置
http://codevs.cn/problem/1204/ 1204 寻找子串位置 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 青铜 Bronze 题解 查看运行结果 ...
- [转]10个顶级的CSS UI开源框架
随着CSS3和HTML5的流行,我们的WEB页面不仅需要更人性化的设计理念,而且需要更酷的页面特效和用户体验.作为开发者,我们需要了解一些宝贵的CSS UI开源框架资源,它们可以帮助我们更快更好地实现 ...
- Java基础(2):Java中的四个跳转语句总结goto,break,continue,return
跳转控制语句 Java中的goto是保留字,目前不能使用.虽然没有goto语句可以增强程序的安全性,但是也带来很多不便,比如说,我想在某个循环知道到某一步的时候就结束,现在就做不了这件事情.为了弥补这 ...
- oracle,sqlserver,mysql 命令行 开启、关闭所需要的服务
ORACLE需要开启的服务 需要启动的服务: 口令: 启动Oracle 11g服务: (下面的可以作为bat 脚本,直接运行便可以不用去自己去启动和关闭服务了.) @echo off @ EC ...
- C main
#include <stdio.h> int main(int argv, char* argc[]) { printf("argv is %d", argv); // ...
- 关于Linux系统basename函数缺陷的思考
某模块作为前台进程独立运行时,运行命令携带命令行参数:作为某平台下守护进程子进程运行时,需要将命令行参数固化在代码里.类似如下写法: char *argv[] = {"./DslDriver ...
- 关于.Net Remoting 和 Web Servcie的比较
参照文献 http://www.cnblogs.com/shinehouse/articles/3001955.html http://www.cnblogs.com/paper/archive/20 ...
- 夺命雷公狗jquery---3普通选择器
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...