最佳调度问题
来源:互联网 发布:php的进程是什么 编辑:程序博客网 时间:2024/06/01 07:52
#include <iostream>#include <fstream>#include <queue>#include <cmath>using namespace std;const int INF = 100000;const int MAX = 50; int n, k; //任务数,机器数int time[MAX]; //完成任务需要时间 class Node{public: int dep; //当前层 int time; //完成当前任务的时间 int *machine; //各机器完成任务后的时间 Node(int d, int t) { machine = new int[k+1]; dep = d; time = t; } int getTime() //计算完成当前任务需要的时间 { int t = machine[1]; for(int i=2; i<=k; i++) if(t < machine[i]) t = machine[i]; return t; } //完成任务时间小的先出队列 bool operator < (const Node &node) const { return time >= node.time; }};int search(){ priority_queue<Node> q; Node enode(0, 0); for(int j=1; j<=k; j++) enode.machine[j] = 0; int best = INF; while(true) { if(enode.dep == n) { if(enode.time < best) { best = enode.time; break; } } else { for(int i=1; i<=k; i++) { Node now(enode.dep+1, 0); copy(enode.machine, enode.machine+k+1, now.machine); now.machine[i] += time[now.dep]; now.time = now.getTime(); if(now.time < best) q.push(now); } } if(q.empty()) break; else { enode = q.top(); cout << enode.dep << " " << enode.time << endl; q.pop(); } } return best;}int main(){ ifstream fin("最佳调度.txt"); cout << "输入任务数:"; fin >> n; cout << n << endl; cout << "输入机器数:"; fin >> k; cout << k << endl; cout << "输入完成任务需要的时间:\n"; for(int i=1; i<=n; i++) { fin >> time[i]; cout << time[i] << " "; } cout << "\n完成全部任务最早时间为:" << search() << endl; cout << endl; cout << endl; fin.close(); return 0;}
0 0
- 最佳调度问题
- 最佳调度问题
- 【9506】最佳调度问题
- 最佳调度问题
- 最佳调度问题
- 最佳调度问题6_8
- 最佳调度问题 解题报告
- 最佳调度问题pascal程序
- 最佳调度问题的回溯算法
- 算法-回溯法解决最佳调度问题
- 搜索与回溯 最佳调度问题
- 回溯法——最佳调度问题
- 最佳调度问题的回溯算法(java实现)
- 《算法导论》实验三:最佳调度问题的回溯算法
- 多机最佳调度
- 11089 多机最佳调度
- kettle调度监控最佳实践
- 开源调度框架Quartz最佳实践
- 布线问题
- 在HTML中用Javascript接收参数
- 如何在高并发分布式系统中生成全局唯一Id
- Contiki OS 数据包发送流程
- SDWebImage的那些事
- 最佳调度问题
- CLRS第十章思考题
- codeblocks编译opencv3小记
- Genymotion foc MAC安装及配置AS过程
- 无优先级运算问题
- 【SSH项目实战】国税协同平台-33.quartz&SimpleTrigge
- javaweb学习总结(四)——Http协议
- MongoDB安装
- 10.缺陷跟踪系统Mantis介绍及安装