The Dragon of Loowater, UVa 11292

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

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

样例输入
2 3
5
4
7
8
4
2 1
5
5
10
0 0 
样例输出
11
Loowater is doomed!

代码如下

#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 20000;
int dragon[maxn];
int knight[maxn];

int main(int argc, const char * argv[]){
  int n;
  int m;
  while(scant("%d%d", &n, &m) && n && m){
      for(int i=0; i<n; i++) scanf("%d", &dragon[i]);    //接收恶龙头的直径
      for(int i=0; i<m; i++) scanf("%d", &knight[i]); //接收骑士的能力
      sort(dragon, dragon + n);
      sort(knight, knight + m);
      int cur = 0;
      int cost = 0;
      for(int i=0; i<m; i++){
          if(knight[i] >= dragon[i]){
              cost += knight[i];
              if(++cur == n) break;     //如何头已经被砍完则提前退出
          }
      }
      if(cur < n) printf("Loowater is doomed!\n");
      else printf("%d\n",cost);
  }
  return 0;
}
时间: 2024-11-07 18:32:24

The Dragon of Loowater, UVa 11292的相关文章

11292 - Dragon of Loowater

例题1  勇者斗恶龙(The Dragon of Loowater, UVa 11292) 你的王国里有一条n个头的恶龙,你希望雇一些骑士把它杀死(即砍掉所有头).村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币.如何雇佣骑士才能砍掉恶龙的所有头,且需要支付的金币最少?注意,一个骑士只能砍一个头(且不能被雇佣两次). [输入格式] 输入包含多组数据.每组数据的第一行为正整数n和m(1≤n,m≤20 000):以下n行每行为一个整数,即恶龙每个头的直

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

[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 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.