简单排序,按每个任务的J值从大到小排序即可。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 1e3+20;
struct node{
int b,j;
bool operator <(const node & x)const{
return j>x.j;
}
}a[maxn];
int n,time,t;
void init(){
for (int i=0; i<n; i++) scanf("%d %d",&a[i].b,&a[i].j);
sort(a,a+n);
time = a[0].b+a[0].j;
t = a[0].b;
}
int kase = 0;
int main(){
while (scanf("%d",&n) && n){
init();
for (int i=1; i<n; i++) {
t+=a[i].b;
time = max(time,t+a[i].j);
}
printf("Case %d: %d\n",++kase,time);
}
return 0;
}
本文介绍了一个简单的任务调度算法实现过程,通过定义任务的结构体并使用C++进行编程,实现了根据任务的特定值J进行排序的功能。该算法首先读取输入的任务数量和每个任务的相关参数,然后将任务按照J值从大到小进行排序,最后计算并输出了完成所有任务所需的时间。
401

被折叠的 条评论
为什么被折叠?



