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

时间:2021-09-07 07:56:01

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

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!

Ondřej Lhoták

代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std; const int maxn=20000;
int n,m,a[maxn+10],b[maxn+10]; void input(){
for(int i=0;i<n;i++) scanf("%d",&a[i]);
for(int j=0;j<m;j++) scanf("%d",&b[j]);
sort(a,a+n);sort(b,b+m);
} void computing(){
if(m<n){
printf("Loowater is doomed!\n");
return ;
}
int i=0,j=0,sum=0;
while(i<n && j<m){
if( a[i]<=b[j] ){
sum+=b[j];
i++;j++;
}else{
j++;
}
}
if(i==n) printf("%d\n",sum);
else printf("Loowater is doomed!\n");
} int main(){
while(scanf("%d%d",&n,&m)!=EOF && (m||n) ){
input();
computing();
}
return 0;
}

uva 11292 Dragon of Loowater (勇者斗恶龙)的更多相关文章

  1. UVA 11292 Dragon of Loowater&lpar;简单贪心&rpar;

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

  2. &lbrack;ACM&lowbar;水题&rsqb; UVA 11292 Dragon of Loowater &lbrack;勇士斗恶龙 双数组排序 贪心&rsqb;

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

  3. UVa 11292 - Dragon of Loowater&lpar;排序贪心&rpar;

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

  4. UVa 11292 Dragon of Loowater

    简单贪心 龙头的直径和人的佣金排序,价值小的人和直径小的配 #include<iostream> #include<cstdio> #include<cmath> ...

  5. UVA - 11292 Dragon of Loowater 贪心

    贪心策略:一个直径为X的头颅,应该让雇佣费用满足大于等于X且最小的骑士来砍掉,这样才能使得花费最少. AC代码 #include <cstdio> #include <cmath&g ...

  6. UVa 11292 Dragon of Loowater (水题,排序)

    题意:有n个条龙,在雇佣勇士去杀,每个勇士能力值为x,只能杀死头的直径y小于或等于自己能力值的龙,只能被雇佣一次,并且你要给x赏金,求最少的赏金. 析:很简单么,很明显,能力值高的杀直径大的,低的杀直 ...

  7. UVA它11292 - Dragon of Loowater

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

  8. UVa 11292 The Dragon of Loowater 勇者斗恶龙

    你的王国里有一条n个头的恶龙,你希望雇佣一些骑士把它杀死(也就是砍掉所有的头).村里有m个骑士可以雇佣,一个能力值为 x 的骑士可以砍掉恶龙一个直径不超过 x 的头,且需要支付 x 个金币.如何雇佣骑 ...

  9. Uva11292--------------&lpar;The Dragon of Loowater&rpar;勇者斗恶龙 (排序后贪心)

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

随机推荐

  1. JavaScript 自定义对象

    在Js中,除了Array.Date.Number等内置对象外,开发者可以通过Js代码创建自己的对象. 目录 1. 对象特性:描述对象的特性 2. 创建对象方式:对象直接量.new 构造函数.Objec ...

  2. XSHELL使用隧道

    线上系统中,搭建了一个elasticsearch环境,想要访问页面,发现环境的内网中没有windows机器,无法使用浏览器来直接进行web页面的访问,于是直接使用了XSELL中强大的功能"隧 ...

  3. &ast;&ast;&ast;&ast;K - Alien&&num;39&semi;s Organ

    K - Alien's Organ Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Sub ...

  4. Linux入门&lpar;14&rpar;——Ubuntu常用快捷键

    打开终端:ctrl + alt + T 左右分屏:ctrl + win + 箭头左或者箭头右 显示桌面:Ctrl + win + D 切换工作区:ctrl + alt + 箭头左或者箭头右 新建文件夹 ...

  5. mysql中的范式与范式——读&lt&semi;&lt&semi;高性能mysql&gt&semi;&gt&semi;笔记一

    对于任何给定的数据库通常都有很多表示方法,从完全的范式化到完全的反范式化,以及两者的折中.在范式化的数据库中,每个事实数据会出现并且只出现一次.相反,在反范式化的数据库中,可能会存储在多个地方. 那什 ...

  6. DDD学习笔记1——分层架构

    新旧架构对比图: DDD中的基础设施层包括数据持久化(ORM数据访问),IoC容器实现,AOP实现(安全,日志记录,缓存等) Repository的接口通常放在领域层,具体实现在基础设施层 旧架构的业 ...

  7. java 大数运算&lbrack;转&rsqb;

    用JAVA 实现算术表达式(1234324234324 + 8938459043545)/5 + 343434343432.59845 因为JAVA语言中的long 定义的变量值的最大数受到限制,例如 ...

  8. vs code配置git

    在项目目录执行 git init 修改.git文件夹下的config文件 [core] repositoryformatversion = 0 filemode = false bare = fals ...

  9. Codeforces Round &num;349 &lpar;Div&period; 1&rpar;E&period; Forensic Examination

    题意:给一个初始串s,和m个模式串,q次查询每次问你第l到第r个模式串中包含\(s_l-s_r\)子串的最大数量是多少 题解:把初始串和模式串用分隔符间隔然后建sam,我们需要找到在sam中表示\(s ...

  10. apache下配置php环境

    1. apache下载 http://httpd.apache.org/download.cgi 2. php下载 http://windows.php.net/download/ 3. 配置 apa ...