优先级调度:优先级高的任务先执行。
来源:互联网 发布:高清网络播放机 编辑:程序博客网 时间:2024/06/04 17:53
题目:
输入5组优先级任务。如下图所示
输入代表的意义是:
任务ID,优先级值(值越大,优先级越高),开始时间,持续时间。共5组。
输出代表的意思:
任务ID,执行持续时间,即整个任务执行的顺序。
思路:在做这类题目时,在时间轴上先画出优先级高的时间线,再画优先级低的时间线,当优先级低的时间线被优先级高的时间线挡住的时候,依次往后延续,直到占满它的时间需求。
#include <stdio.h>#include <vector>#include <algorithm>using namespace std;struct task{int ID;int priority;int start;int time;};bool compare(const task& task1, const task& task2){return task1.priority>task2.priority;}int main(){vector<task> vec(5);int coord[300] = { 0 };int a, b, c, d;for (int i = 0; i < 4; ++i){scanf_s("[%d.%d.%d.%d]|", &a, &b, &c, &d);vec[i].ID = a;vec[i].priority = b;vec[i].start = c;vec[i].time = d;}scanf_s("[%d.%d.%d.%d]", &a, &b, &c, &d);vec[4].ID = a;vec[4].priority = b;vec[4].start = c;vec[4].time = d;sort(vec.begin(), vec.end(), compare);for (int i = 0; i < 5; ++i){int begintime = vec[i].start;int spend = 0;for (int j = begintime;; ++j){if (coord[j] == 0){coord[j] = vec[i].ID;spend++;if (spend == vec[i].time) break;}}}int pre = -1;for (int i = 0;; ++i){if (i == 199){printf("%d.%d", coord[i], i - pre);break;}if (coord[i] == coord[i + 1]){}else{printf("%d.%d|", coord[i], i - pre);pre = i;}}return 0;}
0 0
- 优先级调度:优先级高的任务先执行。
- 优先级高的线程并不一定先执行
- 按照优先级的顺序执行任务
- 线程的调度-优先级
- 线程的调度,优先级
- 线程的调度-优先级
- 嵌入式系统设计过程中任务优先级调度的策略
- 实时操作系统的任务调度示例之优先级反转
- ++ -- 的执行优先级
- Hadoop 设置任务执行的队列以及优先级
- Hadoop 设置任务执行的队列以及优先级
- pthread线程优先级的调度
- 线程的调度或优先级
- pthread线程优先级的调度
- 任务优先级
- ucos 改变任务的优先级
- 改变任务的优先级,OSTaskChangePrio()
- Java 代码执行的优先级
- qnx的无人机方案
- com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败
- C十进制转二进制
- 最长子串
- php配置数据库连接机制
- 优先级调度:优先级高的任务先执行。
- 【洛谷 2296】寻找道路
- 字符串与编码
- 制作 OpenStack Windows 镜像
- 百度前端学院任务:听指令的小方块的实现
- 解决 Windows instance 时间不同步问题
- cloudbase-init 自动扩盘的副作用
- 定制 cloud-init
- 图像的边缘检测