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. Linux内核启动分析过程-《Linux内核分析》week3作业

    环境搭建 环境的搭建参考课件,主要就是编译内核源码和生成镜像 start_kernel 从start_kernel开始,才真正进入了Linux内核的启动过程.我们可以把start_kernel看做平时 ...

  2. 《精通移动app测试实战:技术、工具和案例》新书上市

    本书是测试专家.性能测试专家.专业畅销书作者--于涌,多年实战经验的总结,涵盖主流的测试工具,包括众多的测试实例,涵盖单元测试.功能测试.性能测试.UI测试.手游测试.自动化测试.测试用例管理.持续集 ...

  3. FTP基础知识 FTP port(主动模式) pasv(被动模式) 及如何映射FTP

    您是否正准备搭建自己的FTP网站?您知道FTP协议的工作机制吗?您知道什么是PORT方式?什么是PASV方式吗?如果您不知道,或没有完全掌握,请您坐下来,花一点点时间,细心读完这篇文章.所谓磨刀不误砍 ...

  4. 【转】兼容iOS 10 资料整理

    1.Notification(通知) 自从Notification被引入之后,苹果就不断的更新优化,但这些更新优化只是小打小闹,直至现在iOS 10开始真正的进行大改重构,这让开发者也体会到UserN ...

  5. exam help

    http://forceprepare.com/ http://forcecertified.com/certifications/certified-developer/ http://blog.l ...

  6. 解放双手——Android自动化测试

    解放程序猿宝贵的右手(或者是左手) http://blog.csdn.net/eclipsexys/article/details/45622813 --Android自动化测试技巧 Google大神 ...

  7. 将 Book-Crossing Dataset 书籍推荐算法中 CVS 格式测试数据集导入到MySQL数据库

    本文内容 最近看<写给程序员的数据挖掘指南>,研究推荐算法,书中的测试数据集是 Book-Crossing Dataset 提供的亚马逊用户对书籍评分的真实数据.推荐大家看本书,写得不错, ...

  8. 国内市场上 Android 手机屏幕分辨率的比例情况如何?

    http://www.zhihu.com/question/19587205 根据友盟发布的<友盟国内Android数据报告>,前六名分别是: 800×480,32.4% 480×320, ...

  9. UVA 1101 To Add or to Multiply

    首先我们观察加操作和乘操作会对区间产生那些影响.加操作只会平移区间,而乘操作既能移动区间还能放大区间.因此我们不难想到,如果m>1的话乘操作是log级别的,一方面是因为区间的大小不能超过s-r, ...

  10. Android 在xml中配置 float 和 integer 值

    一.float的配置方法 andriod 默认不支持float型的设置,在values 下的新建floats.xml 文件,在内部添加如下代码: <resources> <item ...