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. ASP.NET身份验证的几种方式

    1.windows身份验证 2.  Forms验证 3.Passport验证 4.none http://www.jb51.net/article/30510.htm

  2. Js 30 BOM

    小知识点, 1.document.write()方法: 如果document.write()在一个事件中或window.onload=function(){}这个function里, 那么docume ...

  3. PyQt主窗体设置停靠窗口(QDockWidget)的叠加顺序

    PyQt提供了方便的停靠窗口控件,我们可以很方便的编写一个停靠窗口,代码和效果如下: # -*- coding: utf-8 -*-from PyQt4 import QtGui, QtCore cl ...

  4. Xcode6项目运行在真机上未铺满整个屏幕

    如图 解决见图: 再次运行:

  5. AppStore安装APP发生错误解决方法

    打开网络偏好设置 高级  -> DNS ->  +  ->  114.114.114.114

  6. Fragment使用

    当我们需要动态的多界面切换的时候,就需要将UI元素和Activity融合成一个模块.在2.3中我们一般通过各种Activity中进行跳转来实现多界面的跳转和单个界面动态改变.在4.0或以上系统中就可以 ...

  7. GCD基本使用

    主要概念 队列 dispatch_queue_t,队列名称在调试时辅助,无论什么队列和任务,线程的创建和回收不需要程序员操作,有队列负责. 串行队列:队列中的任务只会顺序执行(类似跑步) dispat ...

  8. c# 课堂总结6 --集合与结构体

    一.集合 使用时必须添加 System.Collections 集合与数组的区别: 1:数组声明了它容纳的元素的类型,而集合不声明.这是由于集合以object形式来存储它们的元素.初始化时集合无需定义 ...

  9. stack around the variable “ ” was corrupted

    用scanf格式控制不当经常发生此错误. 如 short int a=10;  scanf("%d",&a); 应该是%hd; 一般是越界引起的. 参看:http://bl ...

  10. 什么是DNS劫持

    我们知道,某些网络运营商为了某些目的,对DNS进行了某些操作,导致使用ISP的正常上网设置无法通过域名取得正确的IP地址.常用的手段有:DNS劫持和DNS污染. 什么是DNS劫持 DNS劫持就是通过劫 ...