您的位置:首页 > 其它

贪心 UVA 11729 Commando War

2015-07-19 14:04 363 查看
题目传送门

 /*
贪心:按照执行时间长的优先来排序
*/
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

const int MAXN = 1e3 + 10;
const int INF = 0x3f3f3f3f;
struct Node {
int b, j;
bool operator < (const Node &r) const {
return j > r.j;
}
}node[MAXN];

int main(void)      //UVA 11729 Commando War
{
//freopen ("UVA_11729.in", "r", stdin);

int n;    int cas = 0;
while (scanf ("%d", &n) == 1 && n)
{
for (int i=1; i<=n; ++i)
{
scanf ("%d%d", &node[i].b, &node[i].j);
}

sort (node+1, node+1+n);

int ans = 0;    int mx = -1;
for (int i=1; i<=n; ++i)
{
ans += node[i].b;
mx = max (mx, ans + node[i].j);
}

printf ("Case %d: %d\n", ++cas, mx);
}

return 0;
}

/*
Case 1: 8
Case 2: 15
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: