当前位置:网站首页>P1065 [NOIP2006 提高组] 作业调度方案
P1065 [NOIP2006 提高组] 作业调度方案
2022-08-06 03:36:00 【小天狼星_布莱克】
题目描述
我们现在要利用 mm 台机器加工 nn 个工件,每个工件都有 mm 道工序,每道工序都在不同的指定的机器上完成。每个工件的每道工序都有指定的加工时间。
每个工件的每个工序称为一个操作,我们用记号 j-k 表示一个操作,其中 jj 为 11 到 nn 中的某个数字,为工件号;kk 为 11 到 mm 中的某个数字,为工序号,例如 2-4 表示第 22 个工件第 44 道工序的这个操作。在本题中,我们还给定对于各操作的一个安排顺序。
例如,当 n=3,m=2n=3,m=2 时,1-1,1-2,2-1,3-1,3-2,2-2 就是一个给定的安排顺序,即先安排第 11 个工件的第 11 个工序,再安排第 11 个工件的第 22 个工序,然后再安排第 22 个工件的第 11 个工序,等等。
一方面,每个操作的安排都要满足以下的两个约束条件。
对同一个工件,每道工序必须在它前面的工序完成后才能开始;
同一时刻每一台机器至多只能加工一个工件。
另一方面,在安排后面的操作时,不能改动前面已安排的操作的工作状态。
由于同一工件都是按工序的顺序安排的,因此,只按原顺序给出工件号,仍可得到同样的安排顺序,于是,在输入数据中,我们将这个安排顺序简写为 1 1 2 3 3 2。
还要注意,“安排顺序”只要求按照给定的顺序安排每个操作。不一定是各机器上的实际操作顺序。在具体实施时,有可能排在后面的某个操作比前面的某个操作先完成。
例如,取 n=3,m=2n=3,m=2,已知数据如下(机器号/加工时间):
| 工件号 | 工序11 | 工序22 |
|---|---|---|
| 11 | 1/31/3 | 2/22/2 |
| 22 | 1/21/2 | 2/52/5 |
| 33 | 2/22/2 | 1/41/4 |
则对于安排顺序 1 1 2 3 3 2,下图中的两个实施方案都是正确的。但所需要的总时间分别是 1010 与 1212。

当一个操作插入到某台机器的某个空档时(机器上最后的尚未安排操作的部分也可以看作一个空档),可以靠前插入,也可以靠后或居中插入。为了使问题简单一些,我们约定:在保证约束条件(11)(22)的条件下,尽量靠前插入。并且,我们还约定,如果有多个空档可以插入,就在保证约束条件(11)(22)的条件下,插入到最前面的一个空档。于是,在这些约定下,上例中的方案一是正确的,而方案二是不正确的。
显然,在这些约定下,对于给定的安排顺序,符合该安排顺序的实施方案是唯一的,请你计算出该方案完成全部任务所需的总时间。
输入格式
第 11 行为两个正整数 mm, nn,用一个空格隔开, (其中 m(<20)m(<20) 表示机器数,n(<20)n(<20) 表示工件数)
第 22 行:m \times nm×n 个用空格隔开的数,为给定的安排顺序。
接下来的 2n2n 行,每行都是用空格隔开的 mm 个正整数,每个数不超过 2020。
其中前 nn 行依次表示每个工件的每个工序所使用的机器号,第 11 个数为第 11 个工序的机器号,第 22 个数为第 22 个工序机器号,等等。
后 nn 行依次表示每个工件的每个工序的加工时间。
可以保证,以上各数据都是正确的,不必检验。
输出格式
11 个正整数,为最少的加工时间。
输入输出样例
输入 #1复制
2 3 1 1 2 3 3 2 1 2 1 2 2 1 3 2 2 5 2 4
输出 #1复制
10
说明/提示
NOIP 2006 提高组 第三题
题目解析
这是一道模拟题,主要需要考虑以下几个约束条件:
- 每个工件的下一个工序必须在上一个工序之后
- 同一台机器同一时刻只能加工一个工件
- 按题目顺序安排下一个工件
按照题目说的做,不会错。
我的题解一般会放一组福利数据,这次也不例外。洛谷官方数据测试点#2奉上,附解释。
数据
input
3 3
1 1 1 2 3 3 2 2 3
1 2 3
2 1 3
2 3 1
7 2 4
3 2 5
3 2 3
output
18
explain(可怜我画图花了好久)

附:我的代码
#include <stdio.h>
int m, n;
int list[501];
struct Information {
int id;
// 在第 id 台机器上加工
int cost;
// 花费 cost 时间
} a[21][21];
// a[第几个工件][第几步]
int mac[21][100001] = {0};
// mac[机器编号][时间(话说我也不知道时间最大是多少,反正在空间限制内尽量大)]
int step[21] = {0};
// 每个工件加工到了第几步
int las_time[21] = {0};
// 每个工件上次是 las_time[工件编号] 时加工完的
int ans = 0;
int main()
{
scanf("%d%d", &m, &n);
for (int i = 1; i <= m * n; i++) {
scanf("%d", list + i);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf("%d", &a[i][j].id);
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf("%d", &a[i][j].cost);
}
}
// 以上:读入
for (int i = 1; i <= m * n; i++) {
int now = list[i];
step[now]++;
int id = a[now][step[now]].id, cost = a[now][step[now]].cost;
/* 调试代码 */ // printf("%d: now = %d, id = %d, cost = %d\n", i, now, id, cost);
int s = 0;
for (int j = las_time[now] + 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;
}
/* 调试代码 */ // printf("(%d~%d. \n", j - cost + 1, j);
if (j > ans) ans = j;
las_time[now] = j;
break;
}
}
}
printf("%d", ans);
return 0;
}
边栏推荐
- Several common misunderstandings of enterprises and webmasters renting servers in 2022
- Why is NPDP becoming more and more popular?product manager, do you know?
- 【Untitled】
- Fragment的四种跳转方式
- ctf (finalrec)
- Django reports an error ModuleNotFoundError: No module named 'mysqlclient'
- Web3.exceptions.ExtraDataLengthError
- FluentValidation
- NetCore - custom exception handling
- LabVIEW 应用程序视窗始终置于顶层
猜你喜欢

如果一个国家市场效果特别好,我们如何加大这个国家的投放比例。

Internet Security Aid: Free MD5 Decryption Website

The first day of learning MySQL: MySQL overview (basic)

Mysql installation ask for answers

七夕节微信表白墙小程序源码/基于Laravel的表白墙微信小程序源码

leetcode 15. Sum of three numbers

Introduction to Elliptic Curves (4): Elliptic Curve Security, Compared with RSA

全同态加密知识体系整理

【深度学习21天学习挑战赛】备忘篇:模型复用——模型的保存与加载

greenDAO of Android database framework
随机推荐
C Student management system Delete the specified student node (special case)
ALV details are reorganized2022.8.5
数字化智能工厂解决方案47页
[wpf] Detailed explanation of three callbacks for dependency properties
新搭建的国家广告系列,是否要排除掉旧的广告系列?
2022 Alibaba Cloud server configuration selection strategy
What are the big events on Tmall in August 2022?
Fragment的四种跳转方式
Electric power class topic of the question
Is Tmall Qixi Festival cheap in 2022? What discounts will Tmall Qixi Festival have?
2022年天猫七夕价格便宜吗?天猫七夕节有什么优惠?
The product manager of the Internet, NPDP you need to know
全同态加密知识体系整理
jvm: synchronized关键字不同用法产生不同的字节码
Several common misunderstandings of enterprises and webmasters renting servers in 2022
喜欢我们不如加入我们:来投稿吧,稿酬靠谱!
Programmer's first day at work | Daily anecdote
Custom View, and the usage of Canvas (canvas), Paint (brush), Path (path)
Django reports an error ModuleNotFoundError: No module named 'mysqlclient'
leetcode 18. Sum of Four Numbers