首页 > 代码库 > UVa11729

UVa11729

Commando War

题意:求士兵完成任务的最短时间

#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define N 1008struct Node{    int a;    int b;}Susake[N];int comp(Node x, Node y){    return x.b > y.b ? 1 : 0;}int main(int argc, char *argv[]){    int n, i, sum, t, t1;    t = 1;    while(scanf("%d", &n) != EOF && n)    {        sum = t1 = 0;        for(i = 1; i <= n; i++)            scanf("%d%d", &Susake[i].a, &Susake[i].b);        sort(Susake + 1, Susake + n + 1, comp);        for(i = 1; i <= n; i++)        {            t1 += Susake[i].a;            sum = max(sum, t1 + Susake[i].b);        }        printf("Case %d: %d\n", t++, sum);    }    return 0;}