zoukankan      html  css  js  c++  java
  • BZOJ1570: [JSOI2008]Blue Mary的旅行

    【传送门:BZOJ1570


    简要题意:

      给出n,m,t,表示有n个机场,m条单向航线,t个人,每条航线给出起点和终点,以及每天最多售票数

      然后要求t个人从1到达n,每条航线耗费一天的时间,1号点为第一天

      求出最后一个人到达n的最少天数


    题解:

      网络流,二分

      二分天数,然后将每个机场拆成天数+1的点(因为1号点,相当于第0天到达的)

      每个相连的机场,将x的第i天的点,连向y的第i+1天的点流量为售票数

      然后网络流判断就行了


    参考代码:

    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    struct node
    {
        int x,y,c,next,other;
    }a[510000];int len,last[210000];
    void ins(int x,int y,int c)
    {
        int k1=++len,k2=++len;
        a[k1].x=x;a[k1].y=y;a[k1].c=c;
        a[k1].next=last[x];last[x]=k1;
        a[k2].x=y;a[k2].y=x;a[k2].c=0;
        a[k2].next=last[y];last[y]=k2;
        a[k1].other=k2;
        a[k2].other=k1;
    }
    int h[210000],list[210000],st,ed;
    bool bt_h()
    {
        memset(h,0,sizeof(h));h[st]=1;
        list[1]=st;
        int head=1,tail=2;
        while(head!=tail)
        {
            int x=list[head];
            for(int k=last[x];k;k=a[k].next)
            {
                int y=a[k].y;
                if(a[k].c>0&&h[y]==0)
                {
                    h[y]=h[x]+1;
                    list[tail++]=y;
                }
            }
            head++;
        }
        if(h[ed]==0) return false;
        else return true;
    }
    int findflow(int x,int f)
    {
        if(x==ed) return f;
        int s=0,t;
        for(int k=last[x];k;k=a[k].next)
        {
            int y=a[k].y;
            if(a[k].c>0&&h[y]==(h[x]+1)&&f>s)
            {
                t=findflow(y,min(a[k].c,f-s));
                s+=t;
                a[k].c-=t;a[a[k].other].c+=t;
            }
        }
        if(s==0) h[x]=0;
        return s;
    }
    struct edge
    {
        int x,y,t;
    }e[3100];
    int n,m,t;
    bool check(int d)
    {
        len=0;memset(last,0,sizeof(last));
        for(int i=1;i<=m;i++)
        {
            int x=e[i].x,y=e[i].y,t=e[i].t;
            for(int j=1;j<d;j++)
            {
                ins((x-1)*d+j,(y-1)*d+j+1,t);
            }
        }
        st=0;for(int i=1;i<=d;i++) ins(st,i,999999999);
        ed=n*d+1;for(int i=1;i<=d;i++) ins((n-1)*d+i,ed,999999999);
        int ans=0;
        while(bt_h()==true)
        {
            ans+=findflow(st,999999999);
        }
        if(ans>=t) return true;
        else return false;
    }
    int main()
    {
        scanf("%d%d%d",&n,&m,&t);
        for(int i=1;i<=m;i++) scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].t);
        int l=1,r=n+t,ans;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(check(mid+1)==true)
            {
                ans=mid;
                r=mid-1;
            }
            else l=mid+1;
        }
        printf("%d
    ",ans);
        return 0;
    }

     

  • 相关阅读:
    yjh_study_command
    installed_oracle_can't_use
    Database 2 Day DBA guide_Chapter3
    oracle_great_integration_译文
    oracle_set_autocommit
    Database 2 Day DBA guide_Chapter2
    linux_base_commond_two
    linux_base_commond_one
    Oracle_11gR2_概念_第06章_数据字典和动态性能视图_英文词汇
    angular 自定义select选项,tab切换!!!
  • 原文地址:https://www.cnblogs.com/Never-mind/p/8656091.html
Copyright © 2011-2022 走看看