您的位置:首页 > 其它

UVA 11729 - Commando War

2017-09-06 09:15 399 查看
题目大意:有n支队伍,每支队伍有不同的任务,第i支队伍,被安排任务需要bi时间,做任务需要ji时间。计算全部队伍完成任务的最短时间。安排完任务就开始做任务。

解题思路:贪心。按每支队伍执行任务时间的长短排序。然后计算,那支队伍执行时间超出在其之后安排任务最长加上总安排任务时间。

ac代码:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
struct node{
int a;
int b;
}no[1005];
bool compare(node a, node b)
{
if (a.b != b.b)
return a.b > b.b;
}
int main()  
{  
int n, sum;
int temp, max1, num=1;
while (scanf("%d", &n)!=EOF && n){
sum = 0;
for (int i=0; i<n; i++){
scanf("%d%d", &no[i].a, &no[i].b);
sum += no[i].a;
}
sort(no, no+n, compare);
max1 = sum;
temp = 0;
for (int i=0; i<n; i++){
max1 -= no[i].a;
if (no[i].b - max1 > temp)
temp = no[i].b - max1; 
}
printf("Case %d: %d\n", num++, sum+temp);
}
return 0;  
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: