您的位置:首页 > 其它

uva 11729 Commando War

2014-06-08 23:02 344 查看
贪心算法排序,最后加上长度

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct T{
int b,j;
friend bool operator<(const T& p, const T& q){
return p.j > q.j;
}
}arr[1010];
int main(int argc, char const *argv[])
{
int n,cnt = 0;
while(cin >> n && n){
for(int i = 0; i < n; i++)
cin >> arr[i].b >> arr[i].j;
sort(arr,arr+n);
int tmp = 0, mx = 0;
for(int i = 0; i < n; i++){
tmp += arr[i].b;
mx = max(mx,arr[i].j + tmp);
}
printf("Case %d: %d\n", ++cnt,mx);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: