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. FFT算法

    FFT算法的完整DSP实现 傅里叶变换或者FFT的理论参考: [1] http://www.dspguide.com/ch12/2.htm The Scientist and Engineer's G ...

  2. 2015 款 Macbook Pro 的 ForceTouch 触控板开启 三指拖动

    RT, 默认的触控板设置中没有了三指拖动这个选项, 但是可以通过勾选 辅助功能 -> 鼠标与触控板 -> 触控板选项 中的 启用拖移 来启用三指拖动...

  3. Qt 操作 pdf 文件

    写了好久的东西,不小心按了下返回键就没了.CSDN居然没自动保存,坑爹啊 原本还有很多信息的,现在直入正题吧. QT没有内置PDF操作的功能(其实有一个,QPrinter,不过只能写不能读,基本是半残 ...

  4. win7下wordPress本地搭建博客详解(深度亲测整理---傻瓜式详细教程)

    搭建一个wordPress作为一个个人博客本来是特别简单的事情,但是网上的各种转载让初学者举步维艰,我就本身条件而言,会java EE,懂mysql都花费了我好长时间才搭建好本地博客. 注意:这个是本 ...

  5. 建立Go工作环境

    最近在折腾Go语言,找了个开源项目nsq研究源代码.不过前两天不小心把系统搞挂了,这次又要重做一遍,记录一下,备忘. 准备: 1. vim+golang插件+ctags(新版本支持Go) 2. Go1 ...

  6. 手势滑动结束 Activity(一)基本功能的实现

    喜欢听音乐的朋友可能都看过天天动听这款 app, 这款 app 有一个亮点就是在切换页面(Fragment)的时候能够通过手势滑动来结束当前页面.这里先说一下,我为什么会这么关心这个功能呢,由于前两天 ...

  7. eclipse如何设置成保护眼的背景色

    链接地址:http://jingyan.baidu.com/article/2a138328b5d9ea074a134fc7.html 长时间的使用eclipse开发会很累吧  设置一个保护眼睛的豆沙 ...

  8. javascript笔记整理(事件)

    一.事件驱动 1.事件javascript侦测到的用户的操作或是页面的一些行为(怎么发生的) 2.事件源引发事件的元素(发生在谁的身上) 3.事件处理程序对事件处理的程序或是函数 (发生了什么事) 二 ...

  9. Qt 状态机框架学习(没学会)

    Qt状态机框架是基于状态图XML(SCXML) 实现的.从Qt4.6开始,它已经是QtCore模块的一部分.尽管它本身是蛮复杂的一套东西,但经过和Qt的事件系统(event system).信号槽(s ...

  10. 双卡双待支持双电池 夏新N808深度评测_夏新手机评测-泡泡网

    双卡双待支持双电池 夏新N808深度评测_夏新手机评测-泡泡网 双卡双待支持双电池 夏新N808深度评测