UVa 11292 The Dragon of Loowater 【贪心】

题意:有一条有n个头的恶龙,有m个骑士去砍掉它们的头,每个骑士可以砍直径不超过x的头,问怎样雇佣骑士,使花的钱最少

把头的直径从小到大排序,骑士的能力值也从小到大排序,再一个一个地去砍头

 1 #include<iostream>  

 2 #include<cstdio>  

 3 #include<cstring> 

 4 #include <cmath> 

 5 #include<stack>

 6 #include<vector>

 7 #include<map> 

 8 #include<set>

 9 #include<queue> 

10 #include<algorithm>  

11 using namespace std;

12 

13 typedef long long LL;

14 const int INF = (1<<30)-1;

15 const int mod=1000000007;

16 const int maxn=50005;

17 

18 int a[maxn],b[maxn];

19 int n,m;

20 

21 int main(){

22     while(scanf("%d %d",&n,&m) != EOF && n && m){

23         memset(a,0,sizeof(a));

24         memset(b,0,sizeof(b));

25         for(int i=1;i<=n;i++) scanf("%d",&a[i]);

26         for(int i=1;i<=m;i++) scanf("%d",&b[i]);

27         sort(a+1,a+n+1);

28         sort(b+1,b+m+1);

29         

30         int ans = 0;

31         int cnt = 1;

32         for(int i=1;i<=m;i++){

33             if(b[i] >= a[cnt]) ans += b[i],cnt++;

34             if(cnt == n+1 ) break;

35         }

36         if(cnt <= n) printf("Loowater is doomed!\n");

37         else printf("%d\n",ans);

38     }

39     return 0;

40 }
View Code

 

你可能感兴趣的:(water)