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

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

2 3

5

4

7

8

4

2 1

5

5

10

0 0

SAMPLE OUTPUT

11

Loowater is doomed!

题意:有一条龙有n个头,第i个头的直径为xi,城市里有m个勇者,第i个勇者可以砍下直径小于等于xi的龙的头颅,每个勇者只会挥剑一次,且收费yi,你想消灭这条恶龙,使用尽可能少的钱。。。。

思路:量才而用,能力越大的勇者收费也就越高,那么就可以确定这样的贪心策略,每次都使用大于等于xi且值尽可能地小的那个勇士,还可以把勇者和龙头都从小到大排序,这样,前面被弃选的那些勇者也绝不可能被后面的龙头选上

#include <iostream>
#include <algorithm>
#include <cstdio>
#define RPE(i,n) for(int i=1;i<=(n);i++)
using namespace std;
const int maxn=2e4+;
int a[maxn],b[maxn];
int main()
{
int m,n;
while(cin>>n>>m&&n)
{
RPE(i,n) cin>>a[i];
RPE(i,m) cin>>b[i]; sort(a+,a+n+);
sort(b+,b+m+); int sum=; int cnt=;
RPE(i,m)
{
if(b[i]>=a[cnt])
{
sum+=b[i];
cnt++;
}
if(cnt>n) break;
}
if(cnt<=n) cout<<"Loowater is doomed!"<<endl;
else cout<<sum<<endl;
}
return ;
}

勇者斗恶龙 UVA 11292的更多相关文章

  1. 勇者斗恶龙 uva 11292(简单贪心)

    思路:先将龙和士兵进行分别排序从小到大.然后,每次找当前最小龙的第一个大于它的骑手之后退出,开始下一个龙,重复上一次操作. #include<iostream> #include<a ...

  2. 算法 UVA 11292

    ***从今天开始自学算法. ***代码是用c++,所以顺便再自学一下c++ 例题1  勇者斗恶龙(The Dragon of Loowater, UVa 11292) 你的王国里有一条n个头的恶龙,你 ...

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

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

  4. cogs 1405. 中古世界的恶龙[The Drangon of Loowater,UVa 11292]

    1405. 中古世界的恶龙[The Drangon of Loowater,UVa 11292] ★   输入文件:DragonUVa.in   输出文件:DragonUVa.out   简单对比时间 ...

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

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

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

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

  7. UVa 11292 勇者斗恶龙

    https://vjudge.net/problem/UVA-11292 题意:有n条任意个头的恶龙,你希望雇一些其实把它杀死.一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币 ...

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

    首先先看一下这道题的英文原版... 好吧,没看懂... 大体意思就是: 有一条n个头的恶龙,现在有m个骑士可以雇佣去杀死他,一个能力值为x的勇士可以砍掉直径不超过x的头,而且需要支付x个金币.如何雇佣 ...

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

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

随机推荐

  1. 洛谷 P2038 无线网络发射器选址 —— 二维树状数组

    题目:https://www.luogu.org/problemnew/show/P2038 大水题暴露出我的愚蠢. 用二维树状数组,然而居然忘了它应该那样写,调了一个小时: 正方形可以超出外面,只要 ...

  2. svchost.exe 占用内存过多

    http://www.tomshardware.com/forum/20583-63-svchost-netsvcs-speed By Lokesh Chandra: Just Go to Contr ...

  3. bzoj 1087: [SCOI2005]互不侵犯King【状压dp】

    显然是状压,设f[i][j][k]为1到i行选j个king,并且第i行状态为k的方案数,判断是否可行然后枚举转移即可 先把可行状态预处理出来会变快 #include<iostream> # ...

  4. maptalks 如何加载 ArcGIS 瓦片图层

    最近需要加载 ArcGIS 瓦片图层,运行官网加载 ArcGIS 瓦片图层的 demo 是没有问题的.如果把 ArcGIS 瓦片图层 URL 换成是自已发布的 ArcGIS 地图服务,发现加载不出来, ...

  5. Android项目模块化遇到的问题

    1.问题背景 gradle 4 MacOs 10.14.3 Android Studio 3 在android模块化的时候,例如,有两个模块,一个是usercenter,另一个是common. 其中u ...

  6. 思维题+set URAL 1718 Rejudge

    题目传送门 /* 题意:数据加10组,再删掉第6组数据,问rejudge后最少最多几个作者收到邮件 思维题:当错在6时结果是不一定,错在7时是一定改变,因为会变成6 思路没错,但用结构题排序一直WA, ...

  7. 二分图判定+点染色/并查集 BestCoder Round #48 ($) 1002 wyh2000 and pupil

    题目传送门 /* 二分图判定+点染色:因为有很多联通块,要对所有点二分图匹配,若不能,存在点是无法分配的,no 每一次二分图匹配时,将点多的集合加大最后第一个集合去 注意:n <= 1,no,两 ...

  8. Javascript 排序算法(转)

    1.快速排序 class QuickSort { Sort(originalArray) { // 复制 originalArray 数组防止它被修改 const array = [...origin ...

  9. duilib属性

    原文转载自:http://blog.csdn.net/lixiang987654321/article/details/45008441 这里我想讲解一下duilib中的一些属性的理解,当然这是一篇永 ...

  10. Java编程思想读书笔记_第7章

    final关键字类似const: import java.util.*; public class FinalData { static Random rand = new Random(47); f ...