ACM Computer Factory POJ - 3436

ACM Computer Factory
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 8464 Accepted: 3080 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 ofP 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 ofith machine is represented as by 2 P + 1 integers Qi Si,1Si,2...Si,P Di,1Di,2...Di,P, whereQi specifies performance, Si,j — input specification for partj, Di,k — output specification for partk.

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, thenM descriptions of the connections. Each connection between machines A and B must be described by three positive numbers A B W, whereW 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

[Submit]   [Go Back]   [Status]   [Discuss]


题意:给出N台机器,流水线作业装配电脑,每台电脑有P种配件,每台机器有特定的输入输出:

0表示电脑没有此配件,1表示有此配件,机器输入参数中的2表示输入的电脑配件可有可无

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
用样例分析:机器1可把状态(0,0,0)转换成(0,1,0),再由机器3转换成(1,1,1)即完成装配,单位时间装配了15台


分析:

拆点:一台机器拆分出输入和输出两个点

容量:从超级源点s到起点(状态全0),从终点(状态全1)到超级终点t,不同机器之间,容量均为INF,输入和输出之间容量设为单位时间操作次数;


Ac code:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
const int INF =0x3f3f3f3f;
const int N=1000+50;


int w[N];
int in[N][N];
int out[N][N];
int n,p;

struct Edge {
    int from,to,cap,flow;
};
vector<Edge> edge;
vector<int> G[N];
int pre[N];//记录路径
int vis[N];//起点到i的可改进量

bool bfs(int s,int t) {
    memset(vis,0,sizeof(vis));
    queue<int>q;
    q.push(s);
    vis[s]=INF;
    while(!q.empty()) {
        int x=q.front();
        q.pop();
        for(int i=0; i<G[x].size(); i++) {
            Edge& e=edge[G[x][i]];
            if(!vis[e.to]&&e.cap>e.flow) {
                vis[e.to]=min(vis[x],e.cap-e.flow);
                pre[e.to]=G[x][i];
                q.push(e.to);
            }
        }
    }
    return vis[t];
}

int max_flow(int s,int t) {
    int flow=0;
    while(bfs(s,t)) {
        for(int u=t; u!=s; u=edge[pre[u]].from) {
            edge[pre[u]].flow+=vis[t];
            edge[pre[u]^1].flow-=vis[t];
        }
        flow+=vis[t];
    }
    return flow;
}
void add_edge(int from,int to,int cap) {
    edge.push_back((Edge) {from,to,cap,0});
    edge.push_back((Edge) {to,from,0,0});
    int m=edge.size();
    G[from].push_back(m-2);
    G[to].push_back(m-1);
}


int isStart(int x[]) {
    for(int i=1; i<=p; i++) {
        if(x[i]==1) return 0;
    }
    return 1;
}

int isEnd(int x[]) {
    for(int i=1; i<=p; i++) {
        if(x[i]==0) return 0;
    }
    return 1;
}

int isInAndOut(int in[],int out[]) {
    for(int i=1; i<=p; i++) {
        if(in[i]!=out[i]&&in[i]!=2) return 0;   //等于2可以任意
    }
    return 1;
}


void init(int n) {
    for(int i=0; i<=n; i++) {
        G[i].clear();
    }
    memset(in,0,sizeof in);
    memset(out,0,sizeof out);
    //memset(pre,0,sizeof pre);
}


int main() {
    while(~scanf("%d%d",&p,&n)) {
        int s=0;
        int t=2*n+1;
        init(t);
        for(int i=1; i<=n; i++) {
            scanf("%d",&w[i]);
            //拆点,入点和出点
            for(int j=1; j<=p; j++)
                scanf("%d",&in[i][j]);
            for(int j=1; j<=p; j++)
                scanf("%d",&out[i][j]);
            if(isStart(in[i])) add_edge(s,i,INF);       //1~n为入点
            if(isEnd(out[i])) add_edge(n+i,t,INF);      //n+1~2n为出点
        }

        for(int i=1; i<=n; i++) {
            add_edge(i,i+n,w[i]);
            for(int j=1; j<=n; j++) {
                if(i==j) continue;
                if(isInAndOut(in[i],out[j])) {
                    add_edge(j+n,i,INF);                //刚好可以连接
                }
            }
        }

        int ans=max_flow(s,t);
        int cnt=0;
        int path[N][3];
        for(int u=n+1; u<t; u++)for(int i=0; i<G[u].size(); i++) {
            Edge& e=edge[G[u][i]];
            if(e.to>0&&e.to<=n&&e.flow>0){
                path[cnt][0]=u-n;
                path[cnt][1]=e.to;
                path[cnt++][2]=e.flow;
            }
        }

        printf("%d %d\n",ans,cnt );
        for(int i=0;i<cnt;i++){
            printf("%d %d %d\n",path[i][0],path[i][1],path[i][2] );
        }
    }
    return 0;
}






【复现】并_离网风光互补制氢合成氨系统容量-调度优化分析(Python代码实现)内容概要:本文围绕“并_离网风光互补制氢合成氨系统容量-调度优化分析”的主题,提供了基于Python代码实现的技术研究与复现方法。通过构建风能、太阳能互补的可再生能源系统模型,结合电解水制氢与合成氨工艺流程,对系统的容量配置与运行调度进行联合优化分析。利用优化算法求解系统在不同运行模式下的最优容量配比和调度策略,兼顾经济性、能效性和稳定性,适用于并网与离网两种场景。文中强调通过代码实践完成系统建模、约束设定、目标函数设计及求解过程,帮助读者掌握综合能源系统优化的核心方法。; 适合人群:具备一定Python编程基础和能源系统背景的研究生、科研人员及工程技术人员,尤其适合从事可再生能源、氢能、综合能源系统优化等相关领域的从业者;; 使用场景及目标:①用于教学与科研中对风光制氢合成氨系统的建模与优化训练;②支撑实际项目中对多能互补系统容量规划与调度策略的设计与验证;③帮助理解优化算法在能源系统中的应用逻辑与实现路径;; 阅读建议:建议读者结合文中提供的Python代码进行逐模块调试与运行,配合文档说明深入理解模型构建细节,重点关注目标函数设计、约束条件设置及求解器调用方式,同时可对比Matlab版本实现以拓宽工具应用视野。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值