0
点赞
收藏
分享

微信扫一扫

作业调度方案

栖桐 2022-02-07 阅读 62
模拟算法

在这里插入图片描述

在这里插入图片描述

输入格式

输出格式

示例:
输入:

输出:

模拟题,注意题中的约束条件
每个工件的下一个工序必须在上一个工序之后
同一台机器同一时刻只能加工一个工件
按题目顺序安排下一个工件
代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
struct node{
    int id;
    int cost;
}a[21][21];
int mac[21][N];
int step[21];
int last[21];
int ans;
int b[1005];
int main()
{
    ios::sync_with_stdio(false);
    int m,n;
    cin>>m>>n;
    for(int i=1;i<=n*m;i++)
        cin>>b[i];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>a[i][j].id;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>a[i][j].cost;
    for(int i=1;i<=n*m;i++){
        step[b[i]]++;
        int id = a[b[i]][step[b[i]]].id;
        int cost = a[b[i]][step[b[i]]].cost;

        int s=0;
        for(int j=last[b[i]]+1;;j++){
            if(mac[id][j]==0)
                s++;
            else
                s=0;
            if(s==cost){
                for(int k=j-cost+1;k<=j;k++){
                    mac[id][k]=1;
                }
                if(j>ans)
                    ans=j;
                last[b[i]]=j;
                break;
            }
        }
    }
    cout<<ans;
    return 0;
}
举报

相关推荐

0 条评论