栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 3614 Sunscreen

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 3614 Sunscreen

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N=6000,M=1000000;const int inff=1<<29;int head[N],nc;struct edge{    int x,y,next;    int cap;} edge[M*3];void add(int x,int y,int cap){    edge[nc].x=x;    edge[nc].y=y;    edge[nc].cap=cap;    edge[nc].next=head[x];    head[x]=nc++;    edge[nc].x=y;    edge[nc].y=x;    edge[nc].cap=0;    edge[nc].next=head[y];    head[y]=nc++;}int num[N],h[N],S,T,n;int findpath(int x,int flow){    if(x==T)        return flow;    int res=flow,pos=n-1;    for(int i=head[x]; i!=-1; i=edge[i].next)    {        int y=edge[i].y;        if(h[x]==h[y]+1&&edge[i].cap>0)        { int tp=findpath(y,min(edge[i].cap,res)); res-=tp; edge[i].cap-=tp; edge[i^1].cap+=tp; if(!res||h[S]==n)     return flow-res;        }        if(edge[i].cap>0&&h[y]<pos) pos=h[y];    }    if(res==flow)    {        num[h[x]]--;        if(num[h[x]]==0)        { h[S]=n; return flow-res;        }        h[x]=pos+1;        num[h[x]]++;    }    return flow-res;}int Sap(){    memset(h,0,sizeof(h));    memset(num,0,sizeof(num));    int ans=0;    while(h[S]!=n)        ans+=findpath(S,inff);    return ans;}int cow[3000][2];int main(){    int c,l;    while(scanf("%d%d",&c,&l)!=EOF)    {        nc=0;        memset(head,-1,sizeof(head));        n=c+l+2;        S=0,T=n-1;        for(int i=1;i<=c;i++) scanf("%d%d",&cow[i][0],&cow[i][1]),add(S,i,1);        for(int i=1;i<=l;i++)        { int sp,co; scanf("%d%d",&sp,&co); add(i+c,T,co); for(int j=1;j<=c;j++)     if(cow[j][0]<=sp&&cow[j][1]>=sp)         add(j,i+c,1);        }        printf("%dn",Sap());    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/367238.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号