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!
 #include <stdio.h>
#include <stdlib.h>
#include <assert.h>
//#include <algorithm> int cmp(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
}
int main(int argc, char const *argv[])
{
int n, m;
int *n_array, *m_array;
int i, j;
int cost, cur; while(scanf("%d%d", &n, &m) == && n && m)
{
//printf("%d %d\n", n, m);
n_array = (int *)malloc(sizeof(int) * n);
assert(NULL != n_array);
m_array = (int *)malloc(sizeof(int) * m);
assert(NULL != m_array);
i = ;
while(i != n)
scanf("%d", &n_array[i++]);
i = ;
while(i != m)
scanf("%d", &m_array[i++]);
if(m < n)
{
printf("%s\n", "Loowater is doomed!");
continue;
}
qsort(n_array, n, sizeof(int), cmp);
qsort(m_array, m, sizeof(int), cmp);
cost = cur = ;
for(i = ; i != m; ++i)
{
if(m_array[i] >= n_array[cur])
{
cost += m_array[i];
cur++;
if(cur == n)
break;
}
}
if(cur == n)
printf("%d\n", cost);
else
printf("%s\n", "Loowater is doomed!");
}
return ;
}

UVa11292的更多相关文章

  1. 勇者斗恶龙UVa11292 - Dragon of Loowater

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=s ...

  2. uva11292 Dragon of Loowater

    水题,排序遍历即可 #include<iostream> #include<cstdio> #include<algorithm> using namespace ...

  3. uva-----11292 The Dragon of Loowater

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

  4. uva11292贪心基础题目

    C - 贪心 基础 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bi ...

  5. 【贪心】【Uva11292】 勇者斗恶龙

    直接用白书上的翻译吧 例题1  勇者斗恶龙(The Dragon of Loowater, UVa 11292) 你的王国里有一条n个头的恶龙,你希望雇一些骑士把它杀死(即砍掉所有头).村里有m个骑士 ...

  6. 【题解】 UVa11292 The Dragon of Loowater

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

  7. uva11292 Dragon of Loowater(排序后贪心)

    #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...

  8. UVA11292(排序贪心)

    笔者休息娱乐. ; int n, m, a; ll solve(int n, int m) { ll ans = ; priority_queue<int, vector<int>, ...

  9. UVA11292杀怪

    题意:      一个怪物有N个头,每个头都有半径,然后有M个骑士,每个骑士能砍掉半径小于等于 X[i]的头,花费为X[i],并且一个骑士只能用一次,问砍掉怪物所有头的最小花费. 思路:       ...

随机推荐

  1. WORD2003电子签名插件(支持手写、签章)

    1.引言 WORD电子签名插件,支持手写.本地电子图章.以及网络图章功能.软件使用VC6,以ATL方式编写,软件小巧精致. 这是我学习ATL的成果,学习过程及程序的编写,前前后后共用了一个多月的时间, ...

  2. Android Studio no debuggable applications解决方案2

    android studio 默认是没有开启debuggable 功能的,在tools里打开该功能即可,Tools->Android->Enable ADB Integration. 刚设 ...

  3. linux进阶

    常用命令 rpm -q centos-release 查看centos版本 whereis java 查看文件安装路径 which java 查看可执行文件路径 echo $PATH echo $JA ...

  4. Android布局优化之过度绘制

    如果一个布局十分复杂,那么就需要来排查是否出现了过度绘制,如果出现了,那么很可能会造成刷新率下降,造成卡顿的现象.那么什么是过度绘制呢?过度绘制就是在同一个区域中叠加了多个控件.这就像小时候我们画画, ...

  5. csdn 泄露用户密码害人不浅啊。

    先是京东被盗,接着博客园也登陆不了了.

  6. halcon中variation_model_single实例注释.

    * This example shows how to employ the new extensions of HALCON's variation model operators* to perf ...

  7. C#-DataTable分页代码

    /// <summary> /// DataTable分页并取出指定页码的数据 /// </summary> /// <param name="dtAll&qu ...

  8. Navi.Soft30.产品.DataWindowNet.操作手册

    1概述 1.1功能简介 Sybase公司的PowerBuilder开发工具,在以前VS工具没有成事以前,是相当风光的.微软都要与其合作,学习它Db方面的技术,才成就了SQLServer数据库.PB开发 ...

  9. HL AsySocket 服务开发框架 - 总体思路与架构

    一 背景 最近在园子了浏览了几篇有关Socket文章,得到了一些启发萌生了想要重构公司在2000年用.NET Framework 2.0 与 Visual Studio 2005开发的AsySocke ...

  10. 【网络编程】——linux socket demo

    #include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/socket ...