解题思路:加工刚开始时,A开始加工第一个作业而B闲置,加工即将结束时,A闲置而B加工最后一个作业,所以要使整体时间最短,只需让AB的闲置时间最短,让A执行时间短的进程放前面,B执行时间短的进程放后面。
注意事项:
参考代码:
#include <iostream> #include <cstdio> #include <iomanip> #include <algorithm> using namespace std; const int N = 100000 + 5; class SJ { public: int time; int id; char c; } sj[N]; class JT { public: int a; int b; int c; } jt[N]; int sre[N]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) cin >> jt[i].a; for (int i = 0; i < n; ++i) cin >> jt[i].b; for (int i = 0; i < n; ++i) { sj[i].time = min(jt[i].a, jt[i].b); sj[i].id = i; sj[i].c = jt[i].a <= jt[i].b ? 'a' : 'b'; } for (int i = 0; i < n - 1; ++i) { for (int j = i + 1; j < n; ++j) { if (sj[i].time > sj[j].time) swap(sj[i], sj[j]); } } int head = 0, tail = n-1; for (int i = 0; i < n; ++i) { if (sj[i].c == 'a') sre[head++] = sj[i].id; else sre[tail--] = sj[i].id; } int timeA = 0, timeB = 0; for (int i = 0; i < n; ++i) { timeA += jt[sre[i]].a; if (timeA > timeB) timeB = timeA; timeB += jt[sre[i]].b; } cout << timeB << endl; for (int i = 0; i < n; ++i) cout << sre[i] + 1 << " "; cout << endl; return 0; }
0.0分
3 人评分
震宇大神的杀毒软件 (C++代码)浏览:1173 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:552 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:512 |
1013题解浏览:596 |
printf基础练习2 (C语言代码)浏览:547 |
C语言训练-亲密数 (C语言描述,反正怎么都能对)浏览:2256 |
剪刀石头布 (C语言代码)浏览:1519 |
陶陶摘苹果2 (C++代码)浏览:578 |
整数分类 oj上总是wrong answer浏览:687 |
C语言训练-自由落体问题 (C语言代码)浏览:637 |