您的位置:首页 > 编程语言 > Go语言

#142 (div.2) A. Dragons

2015-07-30 21:57 330 查看
1.题目描述:点击打开链接

2.解题思路:本题利用贪心法解决,首先将strength和bonus定义为一个结构体,首先按照strength从小到大排序,若相同,则按照bonus从大到小排序。然后从头到尾扫描一遍即可。

3.代码:

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<functional>
using namespace std;

#define me(s) memset(s,0,sizeof(s))
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair <int, int> P;

const int N=1000+10;
struct Node
{
    int a,b;
    void read()
    {
        scanf("%d%d",&a,&b);
    }
    bool operator<(const Node&rhs)const
    {
        if(a!=rhs.a)return a<rhs.a;
        return b>rhs.b;
    }
}base
;
int s,n;

int main()
{
    while(~scanf("%d%d",&s,&n))
    {
        for(int i=0;i<n;i++)
            base[i].read();
        sort(base,base+n);
        for(int i=0;i<n;i++)
            if(s<=base[i].a)
        {
            puts("NO");goto x1;
        }
        else
        {
            s+=base[i].b;
        }
        puts("YES");
        x1:;
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: