Task Schedule

几何公主停止了计算几何的学习,专注于新开设的工厂。她引入了M台新机器来处理即将到来的N个任务。每个任务有其特定的开始日期、处理时间和结束日期。通过分析任务与机器之间的关系,解决是否存在可行的调度方案,使得所有任务都能按时完成。通过调整机器分配和任务处理策略,最终实现了有效的任务调度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 

交了10遍,一直TLE,然后改成了邻接表建边dinic,然后又进行了优化,A了。。。

这个题意不难,将源点和任务相连,容量是需要的天数,然后将任务需要在允许的天数内建边,容量为1,最后将所有的天数和汇点建边,容量为m,因为每天最多有m个,因为每个任务至少一天,如果同时工作,所以最多为m,但是最重要的是明白dinic邻接表建边

#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<queue>
#define oo 1<<28
using namespace std;
int n,m,start,end,cnt;
int dep[1100];
int p[1100];
struct node
{
    int u,v,w;
    int next;
} edge[1100000];

void add(int u,int v,int w)
{
    edge[cnt].u=u;
    edge[cnt].v=v;
    edge[cnt].w=w;
    edge[cnt].next=p[u];
    p[u]=cnt++;

    edge[cnt].u=v;
    edge[cnt].v=u;
    edge[cnt].w=0;
    edge[cnt].next=p[v];
    p[v]=cnt++;
}
int BFS()
{
    queue<int>q;
    memset(dep,-1,sizeof(dep));
    dep[start]=0;
    while(!q.empty())
    {
        q.pop();
    }
    q.push(start);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(int i=p[u]; i!=-1; i=edge[i].next)
        {
            if(edge[i].w>0 && dep[edge[i].v]==-1)// 如果可以到达且还没有访问
            {
                dep[edge[i].v]=dep[u]+1;
                q.push(edge[i].v);
            }
        }
    }
    if(dep[end]>0)
        return 1;
    return 0;
}

int find(int i,int sum) // 查找路径上的最小的流量
{
    if(i==end)
        return sum;
    int tmp;
    int t=0;
    for(int j=p[i]; j!=-1; j=edge[j].next)
    {
        int v=edge[j].v;
        int w=edge[j].w;
        if(w>0 && dep[v]==dep[i]+1 && (tmp=find(v,min(sum,w))))
        {
            edge[j].w-=tmp;     //正向减少
            edge[j^1].w+=tmp;     //反向增加
            t+=tmp;
            sum-=tmp;
            if(!sum)
                break;
        }
    }
    if(t)
        return t;
    dep[i]=-1;
    return 0;
}

int Dinic()
{
    int ans=0,tmp;
    while(BFS())//如果能找到一条增广路
    {
        tmp=find(start,oo);//先把开始给标号,oo是因为没有节点控制,先初始为最
        if(tmp==0)
            break;
        ans+=tmp;
    }
    return ans;
}
int main()
{
    int t,i,j,k;
    scanf("%d",&t);
    for(k=1; k<=t; k++)
    {
        cnt=0;
        scanf("%d%d",&n,&m);
        memset(p,-1,sizeof(p));
        int d,u,v,w;
        int sum=0,maxx=0,minn=oo;
        for(i=1; i<=n; i++)
        {
            scanf("%d%d%d",&d,&u,&v);
            sum+=d;
            if(minn>u)
                minn=u;
            if(maxx<v)
                maxx=v;
            add(0,i,d);//将源点和每一个任务相连,权值为每个任务需要的天数
            for(j=u; j<=v; j++)
            {
                add(i,j+n,1);//将每一个任务与他们需要完成得天数区间内相连,权值为1,代表可在此天
            }
        }
        int dd=n+maxx+1;//汇点
        for(i=minn+n; i<=maxx+n; i++)
        {
            add(i,dd,m);//最后将每个天数与汇点相连,权值为m,表示这一天可以有运行m个任务,因为每个任务至少需要一个机器1天,故最多运行m个任务
        }
        start=0,  end=dd;//开始于0,结束于dd
        if(sum==Dinic())
            printf("Case %d: Yes\n\n",k);
        else
            printf("Case %d: No\n\n",k);
    }
    return 0;
}


 

资源下载链接为: https://pan.quark.cn/s/abbae039bf2a DDC控制器是一种智能化的控制设备,广泛应用于建筑自动化、工业控制以及环境监控等领域。它基于先进的微处理器技术,具备强大的数据处理能力和灵活的编程功能。通过预先设定的程序,DDC控制器能够对各类传感器采集的信号进行分析处理,并根据预设的控制策略,精准地驱动执行器完成相应的操作。 在建筑自动化系统中,DDC控制器可用于控制暖通空调系统,实现对温度、湿度、风速等参数的精确调节。它能根据室内外环境的变化,自动调整空调设备的运行状态,确保室内环境的舒适性,同时优化能源消耗。此外,DDC控制器还可用于照明控制,根据自然光照强度和人员活动情况,自动调节灯光亮度,实现节能与舒适性的平衡。 在工业控制领域,DDC控制器可用于监控和控制生产线上的各种设备。它可以实时采集设备的运行数据,如温度、压力、流量等,通过分析这些数据判断设备的运行状态,并及时发出指令调整设备的运行参数,确保生产过程的稳定性和产品质量的可靠性。 DDC控制器具有高度的可靠性和稳定性,能够在恶劣的环境条件下长期稳定运行。其模块化的设计便于安装、调试和维护,用户可以根据实际需求灵活配置控制器的输入输出模块。此外,DDC控制器还具备良好的兼容性,能够与多种类型的传感器和执行器无缝对接,构建完整的自动化控制系统。 总之,DDC控制器凭借其卓越的性能和广泛的应用领域,已成为现代自动化控制系统中不可或缺的核心设备,为实现智能化、高效化和节能化的控制目标提供了有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值