HDU 1902 The Dragon of Loowater

來源:互聯網
上載者:User

標籤:貪心

大白書上第一題,貪心。


排序後掃一遍即可。


#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+10using 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.