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 predators, the geese population was out of control. The people of Loowater mostly kept clear of the geese. Occasionally, a goose would attack
one of the people, and perhaps bite off a finger or two, but in general, the people tolerated the geese as a minor nuisance.

One day, a freak mutation occurred, and one of the geese spawned a multi-headed fire-breathing dragon. When the dragon grew up, he threatened to burn the Kingdom of Loowater to a crisp. Loowater had a major problem. The king was alarmed, and called on his knights
to slay the dragon and save the kingdom.

The knights explained: "To slay the dragon, we must chop off all its heads. Each knight can chop off one of the dragon's heads. The heads of the dragon are of different sizes. In order to chop off a head, a knight must be at least as tall as the diameter of
the head. The knights' union demands that for chopping off a head, a knight must be paid a wage equal to one gold coin for each centimetre of the knight's height."

Would there be enough knights to defeat the dragon? The king called on his advisors to help him decide how many and which knights to hire. After having lost a lot of money building Mir Park, the king wanted to minimize the expense of slaying the dragon. As
one of the advisors, your job was to help the king. You took it very seriously: if you failed, you and the whole kingdom would be burnt to a crisp!

Input Specification:

The input contains several test cases. The first line of each test case contains two integers between 1 and 20000 inclusive, indicating the number n of heads that the dragon has, and the number m of knights in the kingdom. The next n lines
each contain an integer, and give the diameters of the dragon's heads, in centimetres. The following m lines each contain an integer, and specify the heights of the knights of Loowater, also in centimetres.

The last test case is followed by a line containing:

0 0

Output Specification:

For each test case, output a line containing the minimum number of gold coins that the king needs to pay to slay the dragon. If it is not possible for the knights of Loowater to slay the dragon, output the line:

Loowater is doomed!

Sample Input:

2 3
5
4
7
8
4
2 1
5
5
10
0 0

Output for Sample Input:

11
Loowater is doomed!


  1. /*********************************
  2. *   日期:2013-4-19
  3. *   作者:SJF0115
  4. *   题号: 题目11292 - Dragon of Loowater
  5. *   来源:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2267
  6. *   结果:AC
  7. *   来源:UVA
  8. *   总结:
  9. **********************************/
  10. #include<stdio.h>
  11. #include<stdlib.h>
  12. int Dragon[20001],Knights[20001];
  13. //排序函数
  14. int cmp(const void *a,const void *b){
  15. return *(int *)a - *(int *)b;
  16. }
  17. int main ()
  18. {
  19. int i,j,N,M,cost,index;
  20. //freopen("C:\\Users\\XIAOSI\\Desktop\\acm.txt","r",stdin);
  21. while(scanf("%d %d",&N,&M) != EOF){
  22. if(N == 0 && M == 0){
  23. break;
  24. }
  25. //金币
  26. cost = 0;
  27. index = 0;
  28. //头
  29. for(i = 0;i < N;i++){
  30. scanf("%d",&Dragon[i]);
  31. }
  32. //勇士
  33. for(i = 0;i < M;i++){
  34. scanf("%d",&Knights[i]);
  35. }
  36. //排序
  37. qsort(Dragon,N,sizeof(int),cmp);
  38. qsort(Knights,M,sizeof(int),cmp);
  39. //贪心
  40. for(i = 0;i < M;i++){
  41. if(index >= N){
  42. break;
  43. }
  44. if(Knights[i] >= Dragon[index]){
  45. //统计所花金币
  46. cost += Knights[i];
  47. index++;
  48. }
  49. }
  50. //输出
  51. if(index >= N){
  52. printf("%d\n",cost);
  53. }
  54. else{
  55. printf("Loowater is doomed!\n");
  56. }
  57. }
  58. return 0;
  59. }

版权声明:本文博客原创文章,博客,未经同意,不得转载。

UVA它11292 - Dragon of Loowater的更多相关文章

  1. UVA 11292 Dragon of Loowater(简单贪心)

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  2. uva 11292 Dragon of Loowater (勇者斗恶龙)

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  3. [ACM_水题] UVA 11292 Dragon of Loowater [勇士斗恶龙 双数组排序 贪心]

    Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shor ...

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

    Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem.The shore ...

  5. UVa 11292 Dragon of Loowater

    简单贪心 龙头的直径和人的佣金排序,价值小的人和直径小的配 #include<iostream> #include<cstdio> #include<cmath> ...

  6. UVA - 11292 Dragon of Loowater 贪心

    贪心策略:一个直径为X的头颅,应该让雇佣费用满足大于等于X且最小的骑士来砍掉,这样才能使得花费最少. AC代码 #include <cstdio> #include <cmath&g ...

  7. UVa 11292 Dragon of Loowater (水题,排序)

    题意:有n个条龙,在雇佣勇士去杀,每个勇士能力值为x,只能杀死头的直径y小于或等于自己能力值的龙,只能被雇佣一次,并且你要给x赏金,求最少的赏金. 析:很简单么,很明显,能力值高的杀直径大的,低的杀直 ...

  8. 贪心/思维题 UVA 11292 The Dragon of Loowater

    题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...

  9. The Dragon of Loowater

      The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into ...

随机推荐

  1. Android studio多个项目之间怎么实现快速切换?

    Android studio多个项目之间怎么实现快速切换?Android studio中打开的项目太多了,想切换到一个项目很麻烦,怎么才能快速切换到另一个项目中呢?请看下文详细介绍 在对Android ...

  2. Python 数据处理扩展包: pandas 模块的DataFrame介绍(创建和基本操作)

    DataFrame是Pandas中的一个表结构的数据结构,包括三部分信息,表头(列的名称),表的内容(二维矩阵),索引(每行一个唯一的标记). 一.DataFrame的创建 有多种方式可以创建Data ...

  3. SUP (SAP Mobile SDK 2.2) 连接 Sybase SQL Anywhere sample 数据库

    安装了   SAP Mobile SDK 2.2   后发现,这个版本没有自带Sybase SQL Anywhere  数据库. 解决办法: 1. 免费下载 SQL Anywhere Develope ...

  4. 基于visual Studio2013解决C语言竞赛题之0525拉丁方阵

     题目

  5. 基于visual Studio2013解决C语言竞赛题之0521圆盘求和

     题目

  6. 用ASP编写购物车代码

    网上购物已成为生活的潮流,在网上购物之后,想要随时查看自己已买的东西,想要随时删除或改动某件商品数量,要怎么做呢?以下我就来写代码及释义.先来做用户登陆页面(login.asp): <html& ...

  7. Java设计模式菜鸟系列(九)外观模式建模与实现

    转载请注明出处:http://blog.csdn.net/lhy_ycu/article/details/39805735 外观模式(Facade):是为了解决类与类之间的依赖关系的,像spring一 ...

  8. 平衡工作与生活的艺术——GTD简单介绍

    1 开场白 大家好,今天是工作四年来第一次站在部门的分享会议上,所以有讲得不好的地方请大家见谅!而对于今天我想给大家介绍的"GTD工作方法",从2012年接触,认为对工作非常有帮助 ...

  9. ubuntu下配置qt+opengl+opencv

    原地址:http://www.cnblogs.com/aleny-liu/archive/2011/12/16/aleny-Qtnote1.html http://blog.csdn.net/jdh9 ...

  10. Android GsonUtils工具类

    有那么一个开源jar包,叫gson 可以很方便的将java中的对象和字符串相互转化,数据传输和处理的时候,用到的可能性很大 https://github.com/google/gson http:// ...