#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 5;
int n, m, cnt=0;
struct Node{
int b, j;
bool operator < (const Node& p)const {
return j > p.j;
}
}a[maxn];
int main()
{
while(~scanf("%d", &n) && n) {
for(int i=0; i<n; i++)
scanf("%d%d", &a[i].b, &a[i].j);
int ans = 0, SumB = 0;
sort(a, a+n);
for(int i=0;i<n;i++) {
SumB += a[i].b;//分配任务的时间
ans = max(ans, SumB+a[i].j);//ans为0-i之间的士兵执行完任务所花费的时间,判断该士兵执行时花费的时间需不需要等待
}
printf("Case %d: %d\n", ++cnt, ans);
}
return 0;
}
本文介绍了一个基于优先级的任务调度算法实现,通过结构体定义任务并利用比较运算符进行优先级排序,确保了高优先级任务能够优先得到处理。该算法适用于需要有效管理多个任务并根据其紧急程度安排执行顺序的场景。
401

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



