程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> hdu 3572 Task Schedule(網絡流 dinic算法)

hdu 3572 Task Schedule(網絡流 dinic算法)

編輯:C++入門知識

hdu 3572 Task Schedule(網絡流 dinic算法)


Task Schedule

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3412 Accepted Submission(s): 1197


Problem Description Our geometry princess XMM has stoped her study in computational geometry to concentrate on her newly opened factory. Her factory has introduced M new machines in order to process the coming N tasks. For the i-th task, the factory has to start processing it at or after day Si, process it for Pi days, and finish the task before or at day Ei. A machine can only work on one task at a time, and each task can be processed by at most one machine at a time. However, a task can be interrupted and processed on different machines on different days.
Now she wonders whether he has a feasible schedule to finish all the tasks in time. She turns to you for help.

Input On the first line comes an integer T(T<=20), indicating the number of test cases.

You are given two integer N(N<=500) and M(M<=200) on the first line of each test case. Then on each of next N lines are three integers Pi, Si and Ei (1<=Pi, Si, Ei<=500), which have the meaning described in the description. It is guaranteed that in a feasible schedule every task that can be finished will be done before or at its end day.

Output For each test case, print “Case x: ” first, where x is the case number. If there exists a feasible schedule to finish all the tasks, print “Yes”, otherwise print “No”.

Print a blank line after each test case.

Sample Input
2
4 3
1 3 5 
1 1 4
2 3 7
3 5 9

2 2
2 1 3
1 2 2

Sample Output
Case 1: Yes
   
Case 2: Yes

Author allenlowesy
思路:建一個超級源點0,然後假設工作區間長度為T ,再建立[1,T]個點,源點到每個點的流量為M(每天只有M台機器工作),接著,把相應的工作日向後平移T 天,每個工作日到相應的[1,T]的流量為1,到終點的流量也為1.

最後求最大流是否大於等於總總工作量就是了。

#include"stdio.h"
#include"string.h"
#include"queue"
using namespace std;
#define N 1005
#define max(a,b) (a>b?a:b)
#define min(a,b) (a0)
            {
                map[i].w-=tmp;
                map[i^1].w+=tmp;
                cost+=tmp;
                if(cost==lim)
                    break;
            }
            else
                dis[v]=-1;
        }
    }
    return cost;
}
int dinic()
{
    int ans=0,s=0;
    while(bfs())
        ans+=dfs(s,inf);

    //printf("%d\n",ans);
    return ans;
}
int main()
{
    int i,j,T,sum,t1,t2,cas=1;
    int s[505],e[505],p[505];
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&m);
        t1=N;t2=0;
        sum=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d%d%d",&p[i],&s[i],&e[i]);
            t1=min(t1,s[i]);
            t2=max(t2,e[i]);
            sum+=p[i];
        }
        cnt=0;
        memset(head,-1,sizeof(head));
        for(i=t1;i<=t2;i++)      //超級源點到一般源點的流量
        {
            add(0,i,m);
        }
        for(i=1;i<=n;i++)
        {
            for(j=s[i];j<=e[i];j++)
            {
                add(j,j+t2,1);
                add(j+t2,2*t2,1);
            }
        }
        t=t2*2;
        if(sum<=dinic())
            printf("Case %d: Yes\n\n",cas++);
        else
            printf("Case %d: No\n\n",cas++);
    }
    return 0;
}



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved