首页 > 代码库 > HDU 1902 The Dragon of Loowater

HDU 1902 The Dragon of Loowater

大白书上第一题,贪心。


排序后扫一遍即可。


#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<cmath>

#define INF 0x7fffffff
#define eps 1e-8
#define LL long long
#define PI 3.141592654
#define CLR(a,b) memset(a,b,sizeof(a))
#define FORi(n) for(int i=0;i<n;i++)
#define FORj(n) for(int j=0;j<n;j++)
#define FORk(n) for(int k=0;k<n;k++)
#define debug puts("==fuck==")
#define acfun std::ios::sync_with_stdio(false)

#define SIZE 1000+10
using namespace std;
bool cmpa(int a,int b)
{
    return a<b;
}
int v[20001];
int main()
{
    int a[20001],b[20001],i,j,n,m;
    while(scanf("%d%d",&n,&m),n||m)
    {
        FORi(n)
        scanf("%d",&a[i]);
        FORi(m)
        scanf("%d",&b[i]);
        sort(a,a+n,cmpa);
        sort(b,b+m,cmpa);
        int sum=0;
        CLR(v,0);
        bool ok=0;
        for(i=n-1;i>=0;i--)
        {
            ok=0;
            FORj(m)
            if(!v[j]&&b[j]>=a[i])
            {
                v[j]=1,sum+=b[j];
                ok=1;break;
            }
            if(!ok)break;
        }
        if(!ok)puts("Loowater is doomed!");
        else printf("%d\n",sum);
    }
}


HDU 1902 The Dragon of Loowater