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 ...
随机推荐
- HoloLens开发手记 - Unity之Spatial mapping 空间映射
本文主要讨论如何在Unity项目中集成空间映射功能.Unity内置了对空间映射功能的支持,通过以下两种方式提供给开发者: HoloToolkit项目中你可以找到空间映射组件,这可以让你便捷快速地开始使 ...
- Android UI基础之五大布局
Android UI基础之五大布局 Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面.Andro ...
- 一个简单js select插件
现在,通过一个select插件,来介绍一下js插件的构建过程. 1.先上效果图 2.目录构建 (1)这个select插件,我给它起名交hongselect,所以呢,首先建个hongselect的文件夹 ...
- 从零开始写redis客户端(deerlet-redis-client)之路——第一个纠结很久的问题,restore引发的血案
引言 正如之前的一篇博文,LZ最近正在从零开始写一个redis的客户端,主要目的是为了更加深入的了解redis,当然了,LZ也希望deerlet客户端有一天能有一席之地.在写的过程当中,LZ遇到了一个 ...
- Android图片浏览器之缩略图
项目源码:http://files.cnblogs.com/files/tgyf/app.rar. 最近在自学Android,尝试实现一般手机上都存在的图片浏览器,从缩略图开始. 直接上图,这是goo ...
- Bootstrap系列 -- 31.嵌套分组
我们常把下拉菜单和普通的按钮组排列在一起,实现类似于导航菜单的效果.使用的时候,只需要把当初制作下拉菜单的“dropdown”的容器换成“btn-group”,并且和普通的按钮放在同一级 <di ...
- ssh 返回错误 Too many authentic authentication failures for root 的时候检查 ssh 配置
路径 cd /etc/ssh ls -ltr sudo vi sshd_config 改为以下内容(yes): PermitRootLogin yes
- [USACO2005][POJ2226]Muddy Fields(二分图最小点覆盖)
题目:http://poj.org/problem?id=2226 题意:给你一个字符矩阵,每个位置只能有"*"或者“.",连续的横着或者竖的“*"可以用一块木 ...
- JavaBean ,Enterprise Bean(EJB), 三种Bean, 以及POJO
Bean简单的理解,可以理解为组件,一组通用方法的组合: JavaBean就可以称为Java组件,是所有组件的统称,EJB称为企业级 Java组件: 三种Bean: 1). session beans ...
- jquery.validate.js常用扩展函数
$(function () { // 判断整数value是否等于0 jQuery.validator.addMethod("isIntEqZero", function (valu ...