HDU 3572 Task Schedule

Task Schedule

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

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
Source
2010 ACM-ICPC Multi-University Training Contest(13)——Host by UESTC
Recommend
zhouzeyong | We have carefully selected several similar problems for you: 3491 1533 3416 3081 3338

分析:最大流+满流判断(即为:最大流是否等于边上的流量和)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
struct edge{int to,cap,rev;};
const int INF=10000000,max_v=1010;
vector<edge> G[max_v];
int level[max_v],iter[max_v];
void Add_Edge(int from,int to,int cap){
   G[from].push_back((edge){to,cap,G[to].size()});
   G[to].push_back((edge){from,0,G[from].size()-1});
} 
void BFS(int s){
    queue<int> q;
    memset(level,-1,sizeof level );
    level[s]=0; q.push(s); 
    while(!q.empty()){
        int u=q.front();q.pop();
        for(int i=0;i<G[u].size();i++){
            edge &e=G[u][i];
            if(e.cap>0&&level[e.to]<0){
                level[e.to]=level[u]+1;
                q.push(e.to);
            }
        }
    }
}
int DFS(int u,int t,int f){
    int ret=0;
    if(u==t) return f;
    for(int &i=iter[u];i<G[u].size();i++){
        edge &e=G[u][i];
        if(level[u]<level[e.to] && e.cap){
            int d=DFS(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
int max_flow(int s,int t){
    int flow=0;
    for(;;){
        BFS(s);
        if(level[t]<0) return flow;
        memset(iter,0,sizeof iter );
        int f;
        while((f=DFS(s,t,INF))>0){
            flow+=f;
        }
    }
    return flow;
}
int main(){
    int t,i,n,m,x,y,z,sum,j;
    scanf("%d",&t);
    int cas=1;
    while(t--){
        sum=0;
        for(i=0;i<1005;i++) G[i].clear();
        scanf("%d%d",&n,&m);
        int maxx=0;
        for(i=1;i<=n;i++){
            scanf("%d%d%d",&x,&y,&z);
            Add_Edge(0,i,x);
            for(j=y+n;j<=z+n;j++)
                Add_Edge(i,j,1);
            sum+=x;
            maxx=max(maxx,z);
        }
        for(i=n+1;i<=maxx+n;i++)
            Add_Edge(i,1005,m);
        int tmp=max_flow(0,1005);
        printf("Case %d: ",cas++);
        if(tmp==sum) printf("Yes\n\n");
        else printf("No\n\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七情六欲·

学生党不容易~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值