Assigning a task to n individuals time B and time to perform task J each time only one person is assigned a task
Greedy solution assign a task according to the execution time from long to short order and execute the time to calculate the shortest time proof self-certificate
#include <cstdio> #include <algorithm>using namespace std;const int maxn = 1010;struct job{ int B, J; BOOL operator < (const job& x) const{ return j > x.j; }} Job[maxn];int Main () { int n; int cas = 0; while (scanf ("%d", &n)!=eof && N) { for (int i = 0; i < n; ++i) { scanf ("%d%d", &job[i].b, &job [I].J); } Sort (job, job+n); int cnt = 0; int ans = 0; for (int i = 0; i < n; ++i) { cnt + = job[i].b; ans = max (ans, cnt + JOB[I].J); } printf ("Case%d:%d\n", ++cas, ans); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"UVA11729" Commando War