题目大意:

你的王国里有一条n个头的恶龙,你希望雇佣一些骑士把它杀死(即砍掉所有头)。村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币。如何雇佣骑士才能砍掉龙的所有头,且需要支付的金币最少?注意,一个骑士只能砍一个头。(且不能被雇佣两次)。 输入格式

输入包含多组数据。每组数据的第一行为正整数n和m(1<=n,m<=20000);以下n行每行为一个整数,即恶龙每个头的直径;以下m行每行为一个整数,即每个骑士的能力。输入结束标志为n=m=0。 输出格式

对于每组数据,输出最小花费。如果无解,输出“Loowater is doomed!”。

Solution

显然我们要让勇士砍最适合他的龙,所以就考虑直接排序+贪心就好了...

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<math.h>
  5. #include<algorithm>
  6. #include<iostream>
  7. #include<queue>
  8. #define ll long long
  9. #define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
  10. using namespace std;
  11. inline int gi(){
  12. int sum=0,f=1;char ch=getchar();
  13. while(ch>'9' || ch<'0'){if(ch=='-')f=-f;ch=getchar();}
  14. while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
  15. return f*sum;
  16. }
  17. inline ll gl(){
  18. ll sum=0,f=1;char ch=getchar();
  19. while(ch>'9' || ch<'0'){if(ch=='-')f=-f;ch=getchar();}
  20. while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
  21. return f*sum;
  22. }
  23. const int N=20010;
  24. int a[N],b[N];
  25. int main(){
  26. int i,j,n,m,k;
  27. while(scanf("%d%d",&n,&m)==2 && n && m){
  28. for(i=1;i<=n;i++)a[i]=gi();
  29. for(i=1;i<=m;i++)b[i]=gi();
  30. sort(a+1,a+n+1);sort(b+1,b+m+1);
  31. int t=1;ll ans=0;
  32. for(i=1;i<=m && t<=n;i++){
  33. if(a[t]>b[i])continue;
  34. ans+=b[i];t++;
  35. }
  36. if(t>n)printf("%lld\n",ans);
  37. else puts("Loowater is doomed!");
  38. }
  39. return 0;
  40. }

【题解】 UVa11292 The Dragon of Loowater的更多相关文章

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

  2. The Dragon of Loowater

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

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

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

  4. UVA它11292 - Dragon of Loowater

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

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

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

  6. Dragon of Loowater

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=2267" style="color:b ...

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

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

  8. 勇者斗恶龙UVa11292 - Dragon of Loowater

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=s ...

  9. uva11292 Dragon of Loowater

    水题,排序遍历即可 #include<iostream> #include<cstdio> #include<algorithm> using namespace ...

随机推荐

  1. SE新手游操控创新:一个按键=五个技能

    转自:http://www.gamelook.com.cn/2015/01/201299 GameLook报道 / 日本游戏厂商一向擅长搞发明创造,除了诞生了各种烧脑奇葩游戏以外,日本主流手机游戏的核 ...

  2. Unity3D的坑系列:你真想发布WinPhone版吗?

    Unity 4.2加入了支持WinPhone发布,本来是一件令人开心的事情,不过最近听了Unity技术支持的一个事情后就发现,原来发布WinPhone版也是一个坑. 实际上如果你用Unity做小游戏发 ...

  3. ASP.NET页面传值加号变空格解决办法

    只需要把欲传值进行编码 string EncodeId = Server.UrlEncode(id); 加号就变成了 % 2 B  (中间无空格) 然后再传出去. Request.QueryStrin ...

  4. 列举不少于6条的IE与FF脚本兼容性问题,需要写出命令

    (1) window.event: 表示当前的事件对象,IE有这个对象,FF没有,FF通过给事件处理函数传递事件对象 (2) 获取事件源 IE用srcElement获取事件源,而FF用target获取 ...

  5. springboot成神之——spring jdbc的使用

    本文介绍spring jdbc的使用 目录结构 pom配置 properties配置 model层User类 Dao层QueryForListDao config层AppConfiguration 程 ...

  6. C#应用调试C++ dll的方法

    最近碰到个C#应用闪退的问题,由于通讯部分调用了C++工程写的dll,下面介绍一种调试的方法. 右键 启动项目,分别配置常规和和调试即可,如下图. 常规中,输出目录设置为安装目录中dll对应的目录: ...

  7. 微信开发准备(四)--nat123内网地址公网映射实现

    转自:http://www.cuiyongzhi.com/post/37.html 在前面几篇中我们一直说的开发准备工作主要是基于开发框架上的,这里我们说的就逐渐接近开发过程中的实体操作了,如果你之前 ...

  8. Hadoop Serialization -- hadoop序列化详解 (3)【ObjectWritable,集合Writable以及自定义的Writable】

    前瞻:本文介绍ObjectWritable,集合Writable以及自定义的Writable TextPair 回顾: 前面了解到hadoop本身支持java的基本类型的序列化,并且提供相应的包装实现 ...

  9. JAVA基础知识总结15(集合容器)

    集合框架:用于存储数据的容器. 1:对象封装数据,对象多了也需要存储.集合用于存储对象. 2:对象的个数确定可以使用数组,但是不确定怎么办?可以用集合.因为集合是可变长度的. 集合和数组的区别: 1: ...

  10. 安装express.js(NODEJS框架)

    express.js是nodejs的一个MVC开发框架,并且支持jade等多种模板.下面简单来说说express的安装和app.js文件的配置,然后在今后的教程中一步一步使用express.js搭建个 ...