Uva11292 The Dragon of Loowater

原创 2015年11月18日 20:43:59

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 geesepopulationwasoutofcontrol. 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 firebreathing 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 Theinputcontainsseveraltestcases. Thefirstlineofeachtestcasecontainstwointegersbetween1and 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 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 




2 1 


0 0 

Sample Output 


Loowater is doomed!


这题不难,在这里用两个数组分别存放恶龙头的直径和骑士的能力,然后分别将其从小到大排序,然后分别遍历,遍历到的骑士能力只需要大于等于恶龙头的直径就ok,其实能力小于恶龙头的直径就不需要雇佣,雇用过的不能再次雇佣。如果最后便利完了所有的骑士能力,仍有恶龙的头不能被砍掉,则无解,输出“Loowater is doomed!”


#include <stdio.h>
#include <stdlib.h>
#define maxn 200000
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int a[maxn],b[maxn];

int cmp(const void*a,const void*b)
	return *(int*)a-*(int*)b;
int main(int argc, char *argv[]) 
	int n,m,c;
	int i,j;
			printf("Loowater is doomed!\n");
	return 0;

UVA11292 Dragon of Loowater

题目链接:https://vjudge.net/problem/UVA-11292 题意:有n只龙,每个龙的能力为x,你有m个勇士,每个勇士的能力为y,你需要雇佣n个勇士去杀这n只龙,每个勇士雇佣费...
  • Richie_ll
  • Richie_ll
  • 2017年07月28日 13:18
  • 107

UVa11292 - Dragon of Loowater(贪心)

题意:有一个恶龙有n个头,n个头在不同的高度,m个武士,武士只能砍到比它矮的头,而雇佣武士的费用就是武士的高度值,要求以最少的费用来杀到这条恶龙。 思路:在砍一个头时,总是选取比这个头高度大但是在武...
  • wuli2496
  • wuli2496
  • 2017年11月10日 22:55
  • 77

uva11292 Dragon of Loowater 水题

  • u012278856
  • u012278856
  • 2014年05月12日 21:30
  • 316

【UVa11292】Dragon of Loowater 瞎搞

题意:给出n个数和m个数,问如何从m个数中选出n个数使得每个数都大于n里面的一个数,求选出的n个数的最小和。 将n个数和m个数排个序,从头开始找,如果大于就加进来。算法正确性显然。 ...
  • Dadatu_Zhao
  • Dadatu_Zhao
  • 2017年12月31日 17:57
  • 67

uva11292 Dragon of Loowater

 Description Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowat...
  • lh1616
  • lh1616
  • 2014年08月21日 15:38
  • 225

uva11292 - Dragon of Loowater

链接 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=...
  • mcf171
  • mcf171
  • 2015年08月30日 17:42
  • 201

uva11292 - The Dragon of Loowater (贪心)

题目: 有n头恶龙,diameter存其直径,有m个骑士,height存其身高,国王雇佣骑士杀恶龙,佣金为所雇佣骑士身高之和,每个骑士只能杀一条龙且只能被雇一次,求国王需付最少佣金。 思路: 排序...
  • conatic
  • conatic
  • 2016年01月24日 12:24
  • 214

UVa11292 - Dragon of Loowater

今天刘汝佳的算法竞赛入门指南到了,之前的入门经典早看完了,黑书也看了一些,早想买这本书了,一直没机会,到了之后大概的翻了下内容还不错。 因为里面的题目是UVa上面得习题,上去注册了个号,A了书上的第一...
  • PK0071
  • PK0071
  • 2013年11月07日 16:24
  • 811

UVA11292 The Dragon of Loowater

  • qq_16603365
  • qq_16603365
  • 2017年10月14日 22:26
  • 30

UVa11292 Dragon of Loowater

贪心水题。#include #include #include using namespace std; const int MAX = 20005; int n; int m; int sum; ...
  • u010544342
  • u010544342
  • 2013年07月18日 16:37
  • 444
您举报文章:Uva11292 The Dragon of Loowater