11292 - Dragon of Loowater

例题1  勇者斗恶龙(The Dragon of Loowater, UVa 11292)

你的王国里有一条n个头的恶龙,你希望雇一些骑士把它杀死(即砍掉所有头)。村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币。如何雇佣骑士才能砍掉恶龙的所有头,且需要支付的金币最少?注意,一个骑士只能砍一个头(且不能被雇佣两次)。

【输入格式】

输入包含多组数据。每组数据的第一行为正整数nm(1≤n,m≤20 000);以下n行每行为一个整数,即恶龙每个头的直径;以下m行每行为一个整数,即每个骑士的能力。输入结束标志为n=m=0。

【输出格式】

对于每组数据,输出最少花费。如果无解,输出“Loowater isdoomed!”。

【样例输入】

2 3

5

4

7

8

4

2 1

5

5

10

0 0

【样例输出】

11

Loowater is doomed!

【分析】

排序,从小到大开始砍,头数砍够了就输出钱。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define MAXN (20000+10)
int n,m,a[MAXN],b[MAXN];
int main()
{
    while(scanf("%d%d",&n,&m)&&n&&m)
    {
        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
        for(int i=1;i<=m;i++) scanf("%d",&b[i]);
        sort(a+1,a+n+1); sort(b+1,b+m+1);
        int i=1,j=1,cost=0;
        for(;i<=n&&j<=m;i++,j++){
            if(b[j]>=a[i]) cost+=b[j];
            else i--;
        }
        if(i>n) cout<<cost<<endl;
        else cout<<"Loowater is doomed!\n";
    }
    return 0;
}
时间: 2024-10-18 03:47:36

11292 - Dragon of Loowater的相关文章

[2016-03-14][UVA][11292][Dragon of Loowater]

时间:2016-03-14 19:50:12 星期一 题目编号:[2016-03-14][UVA][11292][Dragon of Loowater] 题目大意: 有m个骑士要砍n条龙,每个骑士能看掉龙的头颅当且仅当其实的能力值大于龙的头的直径,每个其实砍掉一条龙需要付出数值上等于能力值的代价,问m个骑士能否砍完所有龙,能则输出最小代价,否则输出"Loowater is doomed!" 输入: 多组数据 每组数据 n m n行 龙头的直径 m行 骑士的能力值 输出: 如果能砍完所有

UVA之11292 Dragon of Loowater

Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predato

UVa 11292 Dragon of Loowater

1 /*UVa 11292 Dragon of Loowater*/ 2 #include<iostream> 3 #include<cstdio> 4 #include<cmath> 5 #include<algorithm> 6 using namespace std; 7 int n,m; 8 int main(){ 9 while(scanf("%d%d",&n,&m) && n!=0 &&

·UVa」 11292 - Dragon of Loowater( 贪心 )

Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predato

UVA它11292 - Dragon of Loowater

Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predato

UVA 题目11292 Dragon of Loowater

Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predato

UVA 11292 Dragon of Loowater(简单贪心)

Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predato

[UVA] 11292 - Dragon of Loowater [贪心+队列]

Problem C: The Dragon of Loowater Time limit: 1.000 seconds Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese.

UVa 11292 - Dragon of Loowater(排序贪心)

Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem.The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese.Due to the lack of predators,the geese population was out of c