The Dragon of Loowater

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<algorithm>
using namespace std; int dra , kni ;
int head[] , peo[] ; int main () {
// freopen ("a.txt" , "r" , stdin ) ;
int money ;
int cnt ;
int p1 ;
while ( scanf ("%d%d" , &dra , &kni ) != EOF ) {
if (dra == && kni == )
break ;
money = ;
cnt = ;
for (int i = ; i < dra ; i++ ) {
scanf ("%d" , &head[i] ) ;
}
for (int i = ; i < kni ; i++ ) {
scanf ("%d" , &peo[i]) ;
} sort (head , head + dra ) ;
sort (peo , peo + kni) ;
/* for (int i = 0 ; i < dia ; i++ ) {
v[cnt] = 1 ;
sum += head[i] ;
}*/
p1 = ; for (int i = ; i < dra ; i++ ) {
if (peo[p1] >= head[i]) {
money += peo[p1++] ;
cnt++ ;
}
else {
i-- ;
p1++ ;
// printf ("1") ;
}
if ( p1 == kni ) {
break ;
}
} if ( cnt == dra ) {
printf ("%d\n" , money ) ;
}
else {
printf ("Loowater is doomed!\n") ;
}
}
return ;
}
分别对两组进行升序排序,之后的操作和归并排序的操作类似
Ondřej Lhoták
The Dragon of Loowater的更多相关文章
- 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 ...
- uva 11292 Dragon of Loowater (勇者斗恶龙)
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- UVA它11292 - Dragon of Loowater
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- UVA 11292 Dragon of Loowater(简单贪心)
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- Dragon of Loowater
option=com_onlinejudge&Itemid=8&page=show_problem&problem=2267" style="color:b ...
- 贪心/思维题 UVA 11292 The Dragon of Loowater
题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...
- Uva11292--------------(The Dragon of Loowater)勇者斗恶龙 (排序后贪心)
---恢复内容开始--- 题目: Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major ...
- [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 ...
- UVa 11292 - Dragon of Loowater(排序贪心)
Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem.The shore ...
随机推荐
- 测试技能积木-AWK的简要用法
做测试工作,经常要分析日志,有的时候活儿还很脏很累,比如抽取符合某些pattern的行,重新格式化等等.有的时候,我们需要也创造一些测试用数据文件.基于上述两种原因,在Unix Like 系统上,一些 ...
- 4.HBase In Action 第一章-HBase简介(1.1.2 数据创新)
As we now know, many prominent internet companies, most notably Google, Amazon, Yahoo!, and Facebook ...
- 使用spring cloud实现分布式配置管理
<7天学会spring cloud系列>之创建配置管理服务器及实现分布式配置管理应用. 本文涉及到的项目: 开源项目:http://git.oschina.net/zhou666/spri ...
- Unity3D 2D游戏中寻径算法的一些解决思路
需求 unity3d的3d开发环境中,原生自带了Navigation的组件,可以很便捷快速的实现寻路功能.但是在原生的2d中并没有相同的功能. 现在国内很多手机游戏都有自动寻路的功能,或者游戏中存在一 ...
- css平时写的时候注意的
1.如果用absolute的时候一定要注意,bottom如果为)的话,一定要注意上一级的relative是否有height. 2.chrome浏览器,我们需要注意的是width包含了padding,但 ...
- AaronYang的C#私房菜[二][提供编程效率的技巧]
前言 我的文章简单易懂,能学到东西.因为复杂的东西,讲起来,好累.阅读者只是膜拜,学不到东西,就是没用的东西,好多文章都是看不下去.我写不出来<大话设计模式>那种为了读者的书,因为没有时间 ...
- 第十七章:jQuery类库
javascript的核心API设计的很简单,但由于浏览器之间的不兼容性,导致客户端的API过于复杂.IE9的到来缓解了这种情况.然而使用javascript的框架或者工具类库,能简化通用操作,处理浏 ...
- jquery.validate.js常用扩展函数
$(function () { // 判断整数value是否等于0 jQuery.validator.addMethod("isIntEqZero", function (valu ...
- iOS -- 生成有logo的二维码
- (void)createLogoImage { NSArray *filter = [CIFilter filterNamesInCategory:kCICategoryBuiltIn]; NSL ...
- JAVA 注解的几大作用及使用方法详解【转】
java 注解,从名字上看是注释,解释.但功能却不仅仅是注释那么简单.注解(Annotation) 为我们在代码中添加信息提供了一种形式化的方法,是我们可以在稍后 某个时刻方便地使用这些数据(通过 解 ...