Time Limit: 1sec    Memory Limit:32MB 
Description
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

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

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
aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAARABIDASIAAhEBAxEB/8QAGAABAAMBAAAAAAAAAAAAAAAAAAMFBwT/xAAlEAACAQQCAQMFAAAAAAAAAAABAgMABAURBiESIjFBMjZxdbP/xAAYAQACAwAAAAAAAAAAAAAAAAAAAwEEBf/EABsRAQEAAgMBAAAAAAAAAAAAAAEAAgMEEyFh/9oADAMBAAIRAxEAPwDQeRW+SyVnctBIkiiScOk87qm0ciP0aZWA8dkEDZA2fcGPCWPI+PXkUt3GIcQjkyQxTGdtMrAhUVQO5CraVd/UB1pa7cnHmbaW5hjxEktoZJJGulnjChWYsT4lvLoHvr3B1vommvuQYaSe/jGSxrW9yXEiCWIiTe9eWohvs/LH8n5ocDh9jlnsER+zt+9wDE9G0uKWO4hSaGRJIpFDI6MCrKewQR7ilVfFPs7B/r4P5rStB8ZJW9KUqIlKUoi//9k=" alt="" /> Copy sample input to clipboard 
2 3
5
4
7
8
4
2 1
5
5
10
0 0
Sample Output
11
Loowater is doomed!
分析:
根据题意,要找到能砍掉所有龙头的最小代价,也就是说所需要的骑士的数量是确定的,那么只需要从小到大找到 n 个满足情况的骑士。
所有对龙头直径和骑士分别排序,然后从龙头的从小到大找符合条件的骑士即可
#include <iostream>
#include <algorithm> using namespace std; int getMinCost(int *dragon, int *warrior, int n, int m) {
sort(dragon, dragon + n);
sort(warrior, warrior + m);
int minCost = ;
int i = , j = ;
for (; i < n && j < m;) {
if (dragon[i] <= warrior[j]) {
minCost += warrior[j];
++i;
}
++j;
}
if (i != n)
minCost = ;
return minCost;
} int main(int argc, char const *argv[])
{
int m, n;
int dragon[];
int warrior[];
while (cin >> n >> m && (n != && m != )) {
for (int i = ; i != n; ++i)
cin >> dragon[i];
for (int i = ; i != m; ++i)
cin >> warrior[i]; int minCost = ;
if (n <= m) {
minCost = getMinCost(dragon, warrior, n, m);
}
if (minCost == )
cout << "Loowater is doomed!" << endl;
else
cout << minCost << endl;
}
return ;
}

sicily 1459. The Dragon of Loowater的更多相关文章

  1. The Dragon of Loowater

      The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into ...

  2. 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 ...

  3. uva 11292 Dragon of Loowater (勇者斗恶龙)

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

  4. UVA它11292 - Dragon of Loowater

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

  5. UVA 11292 Dragon of Loowater(简单贪心)

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

  6. Dragon of Loowater

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=2267" style="color:b ...

  7. 贪心/思维题 UVA 11292 The Dragon of Loowater

    题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...

  8. Uva11292--------------(The Dragon of Loowater)勇者斗恶龙 (排序后贪心)

    ---恢复内容开始--- 题目: Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major ...

  9. [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 ...

随机推荐

  1. c++11 右尖括号>改进

    c++11 右尖括号>改进 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> # ...

  2. oracle 月份中日的值必须介于 1 和当月最后一日之间

    解决方法: 1.用时间字段去关联字符串字段导致此错误.. 如果1.解决不了就看 2.把date'2017-01-01'  换成 to_date('2017-01-01','yyyy-mm-dd')

  3. 洛谷 P2184 贪婪大陆 解题报告

    P2184 贪婪大陆 题目背景 面对蚂蚁们的疯狂进攻,小\(FF\)的\(Tower\) \(defence\)宣告失败--人类被蚂蚁们逼到了\(Greed\) \(Island\)上的一个海湾.现在 ...

  4. 洛谷 P1436 棋盘分割 解题报告

    P1436 棋盘分割 题目描述 将一个8*8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将剩下的两部分中的任意一块继续如此分割,这样割了(n-1)次后,连同最后剩下的矩形棋盘共 ...

  5. Linux及安全实践五——字符集编码

    Linux及安全实践五——字符集编码 一.ASCII码 在表中查找出英文字母LXQ相对应的十六进制数值为: 4c 58 51 在终端中输入命令:vim test1.txt 在vim页面输入命令:%!x ...

  6. Mac显示同一程序的所有窗口

    通过F3键可以显示所有程序的所有窗口到桌面,但是如果窗口太多的话显示出来很难看清. 如果只显示某一个程序的所有窗口就不会乱了. 其实在dock上有一个相应的选项,但是没有快捷键. 开启方法: 在终端上 ...

  7. 遇到问题----gradle-----myeclipse的gradle插件导入项目报错nsupported major.minor version 51.0

    装好了gradle插件之后 想要导入gradle类型的项目,然后在 build model的过程中发现: 报错nsupported major.minor version 51.0 查了下发现是jdk ...

  8. 闲:测试memcpy和std::copy vector之间拷贝

    预测:底层C函数肯定比stl算法快 结果:少量数据底层快,大数据以上则stl对vector的处理可能更好 C/C++: #include <iostream> #include <v ...

  9. Logistic Ordinal Regression

    sklearn实战-乳腺癌细胞数据挖掘(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005269003&a ...

  10. python---基础知识回顾(十)进程和线程(py2中自定义线程池和py3中的线程池使用)

    一:自定义线程池的实现 前戏: 在进行自定义线程池前,先了解下Queue队列 队列中可以存放基础数据类型,也可以存放类,对象等特殊数据类型 from queue import Queue class ...