首页 > 其他 > 详细

UVA 11729 Commando War

时间:2017-04-20 20:00:19      阅读:186      评论:0      收藏:0      [点我收藏+]

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2829


不摘抄题目了;

解析:

 简单贪心思想。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define MAXN 20005
#define RST(N)memset(N, 0, sizeof(N))
using namespace std;

typedef struct Node_ {
    int b, j;
}Node;

Node N[MAXN];
int n;

int cmp(const void *a, const void *b)
{
    Node *p1 = (Node *)a;
    Node *p2 = (Node *)b;
    if(p1->j != p2->j) return p2->j - p1->j;
    else return p2->b - p1->b;
}

int max(int x, int y) { return x>y ? x:y; }

int main()
{
    int cas = 0;
    while(~scanf("%d", &n) && n) {
        for(int i=0; i<n; i++) {
            scanf("%d %d", &N[i].b, &N[i].j);
        }
        qsort(N, n, sizeof(Node), cmp);
        int res = 0, cnt = 0;
        for(int i=0; i<n; i++) {
            cnt += N[i].b;
            res = max(res, cnt+N[i].j);
        }
        printf("Case %d: %d\n", ++cas, res);
    }
    return 0;
}


UVA 11729 Commando War

原文:http://www.cnblogs.com/lytwajue/p/6740162.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!