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! 代码:
题目的大意是 一条大恶龙有很多头,然后你将要派出一些骑士去斩下恶龙的头,每一位骑士只能斩获一个头,但是每派出一个骑士就需要支付一定的货币
,然后问有没有可能斩下所有恶龙的头,若能,最少需要支付多少货币.......!
 #include<cstdio>
#include<algorithm>
using namespace std; const int maxn =+;
int A[maxn] , B[maxn];
int main()
{
int n,m,i;
while(scanf("%d%d",&n,&m)==&&n&&m)
{
for(i= ; i<n ;i++)
scanf("%d",&A[i]);
for(i= ; i<m ;i++)
scanf("%d",&B[i]);
sort(A,A+n); //对A进行从小到大排序
sort(B,B+m); //对B进行从小到大排序
int cur=;
int cost=;
for(i=;i<m;i++)
{
if(B[i]>=A[cur])
{
cost+=B[i];
cur ++ ;
if(cur == n ) break;
}
}
if(cur<n)
printf("Loowater is doomed!\n");
else
printf("%d\n",cost);
}
}

最新文章

  1. 【leetcode】Populating Next Right Pointers in Each Node I &amp; II(middle)
  2. io流对文件读写操作
  3. Moses创建一个翻译系统的基本过程记录,以后会按照每个过程详细说明,并给出每个步骤的参数说明
  4. 快逸报表部署 (一)-- demo连接mysql数据库
  5. string中常用的函数
  6. ASP.NET的分页方法(三)
  7. MultiView空间例子
  8. javascript中的字符串编码、字符串方法详解
  9. 四、正则表达式re模块
  10. mysql系列十、mysql索引结构的实现B+树/B-树原理
  11. android多设备界面适配的利器:属性weight的妙用
  12. Spring Boot 上传文件 获取项目根路径 物理地址 resttemplate上传文件
  13. python数据分析的工具环境
  14. Linux下的MBR分区
  15. linux sed命令查询结果前后批量追加内容(html文件批量修改css,js等文件路径)
  16. 解决Bat脚本中包含中文,运行乱码
  17. Android学习笔记_2_发送短信
  18. UIView和UIImageView 旋转消除锯齿方法
  19. Linux常用命令(补充)-grep
  20. 题解报告:poj 3468 A Simple Problem with Integers(线段树区间修改+lazy懒标记or树状数组)

热门文章

  1. UE4高级功能--初探超大无缝地图的实现LevelStream
  2. FreeSWITCH一些需求应对
  3. linux Chrome 安装
  4. MusigCV安装
  5. factory工厂模式之工厂方法FactoryMethod
  6. JS——ajax login test
  7. python_way day13 paramiko
  8. win 8 pip install 或者 pycharm 安装 paramiko 报错
  9. C# 线程(六):定时器
  10. 51nod 1413 权势二进制 背包dp