首页 > 其他 > 详细

突击战 (uva 11729)贪心

时间:2019-04-15 22:32:53      阅读:171      评论:0      收藏:0      [点我收藏+]

思路:就是把J大的放在前面。为什么这样贪心呢?

看看这个图

技术分享图片

 

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct node{
    int x, y;
    bool operator < (const node &b) const{
        return y>a.y;
    }
};
int n, t, x, y;

int main(){
        while(cin>>n, n){
            vector<node>v;
            for(int i=0;i<n;++i){
                cin>>x>>y;      v.push_back((ndoe){x, y});
            }
            sort(v.begin(), v.end());
            
            int res=0, ans=0;
            for(int i=0;i<n;++i){
                res+=v[i].x;
                ans=max(ans, res+v[i].y);
            }
            cout<<"Case "<<++t<<": "<<ans<<endl;
        }
}

 

突击战 (uva 11729)贪心

原文:https://www.cnblogs.com/ALINGMAOMAO/p/10713553.html

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