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

1A 水题没的说!

Posted by 5D6D2 at 2012-09-15 21:07:38 on Problem 3614
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
const int CMax=2510,NMax=2*CMax;
int nn,C,L,PL,Min[CMax],Max[CMax],P[CMax],NUM[CMax];
struct edge {
    int num,len;
    edge *next,*rev;
}*A[NMax],pool[2*CMax*CMax];
void Build(int x,int y,int z) {
    edge *p=&pool[PL++],*q=&pool[PL++];
    p->num=y;p->len=z;p->next=A[x];A[x]=p;p->rev=q;
    q->num=x;q->len=0;q->next=A[y];A[y]=q;q->rev=p;
}
int level[NMax],q[NMax];
bool makelevel() {
    memset(level,-1,sizeof(level));
    q[0]=0;level[0]=0;
    for(int i=0,bot=1;i<bot;i++) {
        int x=q[i];
        for(edge *p=A[x];p;p=p->next) if(p->len&&level[p->num]==-1){
            level[q[bot++]=p->num]=level[x]+1;
        }
    }
    return level[nn]!=-1;
}
int Find(int a,int alpha) {
    if(a==nn) return alpha;
    int tot=0,tmp;
    for(edge *p=A[a];p&&tot<alpha;p=p->next) {
        if(p->len&&level[p->num]==level[a]+1)
            if(tmp=Find(p->num,min(p->len,alpha-tot))) {
                tot+=tmp;
                p->len-=tmp;
                p->rev->len+=tmp;
            }
    }
    if(!tot) level[a]=-1;
    return tot;
}
int main()
{
    scanf("%d%d",&C,&L);
    nn=C+L+1;
    for(int i=1;i<=C;i++) {
        scanf("%d%d",Min+i,Max+i);
        if(Min[i]>Max[i]) swap(Min[i],Max[i]);
    }
    for(int i=1;i<=L;i++) scanf("%d%d",P+i,NUM+i);
    for(int i=1;i<=L;i++) {
        Build(0,i,NUM[i]);
        for(int j=1;j<=C;j++)
            if(Min[j]<=P[i]&&P[i]<=Max[j]) Build(i,L+j,1);
    }
    for(int i=1;i<=C;i++) Build(L+i,nn,1);
    int tmp,ret=0;
    while(makelevel()) 
        while(tmp=Find(0,100000000)) ret+=tmp;
    printf("%d\n",ret);
    getchar();getchar();
}

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