现在的位置: 首页 > 综合 > 正文

uva 11729 Commando War

2019年11月11日 ⁄ 综合 ⁄ 共 399字 ⁄ 字号 评论关闭

贪心算法排序,最后加上长度

#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;
}
【上篇】
【下篇】

抱歉!评论已关闭.