UVA 11729

来源:互联网 发布:电脑运行apk软件 编辑:程序博客网 时间:2024/06/18 18:34

题目大意:有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;  }
原创粉丝点击