uva 11729
任务执行时间长的先交代
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN (1000+5)
struct node{
int b, j;
bool operator <(const node &a)const{
return j > a.j;
}
};
node per[MAXN];
int main(){
int n, T = 0;
while(scanf("%d", &n) && n){
for(int i = 1; i <= n; i++) scanf("%d%d", &per[i].b, &per[i].j);
sort(per+1, per+n+1);
int ans = 0, now = 0;
ans = per[1].b + per[1].j;
now = per[1].b;
for(int i = 2; i <= n; i++){
now += per[i].b;
int add = now + per[i].j;
if(add > ans) ans = add;
}
printf("Case %d: %d\n", ++T, ans);
}
return 0;
}
本文针对UVA11729题目提供了一种解决方案,通过定义结构体来存储任务的基本时间和交接时间,并使用优先级排序来确定执行顺序,最终计算出最长的任务执行时间。
2万+

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



