Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一直WA,請師兄指點迷津 代碼如下

Posted by chun10161991 at 2010-12-26 17:51:50 on Problem 3436
#include <cstdio>
#define fMIN(a,b) a>b?b:a
#define INF 100000000

int N,P,ans,s[10] = {0,0,0,0,0,0,0,0,0,0},n[10] = {1,1,1,1,1,1,1,1,1,1};
int pl[55][55],pt[55][55];
bool etl[55][55],ett[55][55];
bool vis[55];
struct {
    int u[15],v[15],w,f;
}e[55],te[55];

struct {
    int from,c,t,min;
}state[20000];

bool cmp(int u[],int v[]){
    for (int i=0;i<P;++i)
        if (u[i] + v[i] == 1)
            return 0;
    return 1;
}

bool bfs(){
    for (int i=0;i<N+2;++i)
        vis[i] = 0;
    int front,rear;
    front = rear = 0;
    state[front].c = N;
    state[front].min = INF;
    while (front <= rear && state[front].c != N+1){
        for (int i=0;i<=N+1;++i){
            if (!vis[i] && ett[state[front].c][i] && (i >= N  || te[i].f < te[i].w)){
                state[++rear].c = i;
                state[rear].min = fMIN(te[i].w - te[i].f,state[front].min);                
                state[rear].from = front;
                state[rear].t = 1;
                vis[i] = 1;
            }
            if (!vis[i] && etl[state[front].c][i] && (i >= N  || e[i].f < e[i].w)){
                state[++rear].c = i;
                state[rear].from = front;
                state[rear].min = fMIN(e[i].w - e[i].f,state[front].min);
                state[rear].t = 0;
                vis[i] = 1;
            }
            
        }
        ++front;
    }
    if (front > rear || state[front].c != N+1) return 0;
    int tmp;
    ans += tmp = state[front].min;
    while (front != 0){
        if (state[front].t){
            te[state[front].c].f += tmp;
            pl[state[front].c][state[state[front].from].c] -= tmp;
        }
        else {
            pl[state[state[front].from].c][state[front].c] += tmp;
            e[state[front].c].f += tmp;
            te[state[front].c].w += tmp;    
        }        
        front = state[front].from;
    }
    return 1;
}

int main(){
	while (scanf("%d%d",&P,&N) != EOF){
        ans = 0;
        e[N].f = e[N+1].f = te[N].f = te[N+1].f = 0;
        te[N].w = te[N+1].w = e[N].w = e[N+1].w = INF;
        for (int i=0;i<N+2;++i)
            for (int j=0;j<N+2;++j)
                etl[i][j] = ett[i][j] = pl[i][j] = pt[i][j] = 0;
        for (int i=0;i<N;++i){
            scanf("%d",&e[i].w);
            e[i].f = 0;
            for (int j=0;j<P;++j)
                scanf("%d",&e[i].u[j]);    
            for (int j=0;j<P;++j)
                scanf("%d",&e[i].v[j]);
            for (int j=0;j<P;++j){
                te[i].v[j] = e[i].u[j];
                te[i].u[j] = e[i].v[j];
            }
            etl[i][i] = 0;
            for (int k=0;k<i;++k){
                if (cmp(e[i].v,e[k].u))
                    etl[i][k] = 1;
                if (cmp(e[k].v,e[i].u))
                    etl[k][i] = 1;
            }
            if (cmp(s,e[i].u))
                etl[N][i] = 1;
            if (cmp(e[i].v,n))
                etl[i][N+1] = 1;
        }
        while (bfs());
        int cnt = 0;
        for (int i=0;i<N;++i)
            for (int j=0;j<N;++j)
                if (pl[i][j]) ++cnt;
        printf("%d %d\n",ans,cnt);
        for (int i=0;i<N;++i)
            for (int j=0;j<N;++j){
                if (pl[i][j])
                    printf("%d %d %d\n",i+1,j+1,pl[i][j]);
            }
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator