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. J2EE学习笔记-第二章(Web应用初步)

    首先要理解一些概念的词语,到底这些是什么(当我读懂了后,会逐一填补完整,现在我真的有点混淆) web组件-相当于功能性的组件,就像是零件,汽车的轮胎,汽车的门,所有组件组合后,才能成为一辆车,有时候也 ...

  2. 转:SDL2源代码分析

    1:初始化(SDL_Init()) SDL简介 有关SDL的简介在<最简单的视音频播放示例7:SDL2播放RGB/YUV>以及<最简单的视音频播放示例9:SDL2播放PCM>中 ...

  3. C#之读取web上的xml

    一.使用LINQ读取使用Xdocument上的Load方法,可以快速的加载一个XML文档,然后使用LINQ对 加载XML文档进行查询或其他操作,这里仅简单偏历.所以,一旦查询一组元素有返回元素集,就可 ...

  4. java代码实现如何获取当前经纬度?(安卓的话可以用GPS取)

    import android.app.Activity; import android.os.Bundle; import android.location.*; import android.con ...

  5. Android 中的AIDL,Parcelable和远程服务

    Android 中的AIDL,Parcelable和远程服务      早期在学习期间便接触到AIDL,当时对此的运用也是一撇而过.只到近日在项目中接触到AIDL,才开始仔细深入.AIDL的作用    ...

  6. sublime3 配置node build环境

    折腾了很久,原来如此简单 1.package control  安装nodejs 2.修改Nodejs.sublime-settings文件,将nodejs路径修改成自己的 3.sublime tex ...

  7. Scala 深入浅出实战经典 第60讲:Scala中隐式参数实战详解以及在Spark中的应用源码解析

    王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-87讲)完整视频.PPT.代码下载:百度云盘:http://pan.baidu.com/s/1c0noOt6 ...

  8. thinkphp 关联模型配置代码

    <?php /** * 公司与部门关联模型 */ class CompanyRelationModel extends RelationModel{ //主表名称 protected $tabl ...

  9. Windows 7下安装MongoDB

    1.下载mongodb-win32-x86_64-2008plus-2.6.7-signed.msi(如今最新版本号已经到了3.0) 2.如果为64位操作系统则双击 mongodb-win32-x86 ...

  10. 実行時にMicrosoft.ACE.OLEDB.12.0プロバイダーはローカルコンピュータに登録されていませんが出てしまう

    環境 Windows8 64bit Visual Studio 2010 Access 2010 32bit 接続プロバイダは「Microsoft.ACE.OLEDB.12.0」 対応 Downloa ...