贪心策略:一个直径为X的头颅,应该让雇佣费用满足大于等于X且最小的骑士来砍掉,这样才能使得花费最少。

AC代码

  1. #include <cstdio>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <utility>
  6. #include <string>
  7. #include <iostream>
  8. #include <map>
  9. #include <set>
  10. #include <vector>
  11. #include <queue>
  12. #include <stack>
  13. using namespace std;
  14. #pragma comment(linker, "/STACK:1024000000,1024000000")
  15. #define eps 1e-10
  16. #define inf 0x3f3f3f3f
  17. #define PI pair<int, int>
  18. typedef long long LL;
  19. const int maxn = 2e4 + 5;
  20. int head[maxn], kill[maxn];
  21.  
  22. int main() {
  23. int n, m;
  24. while(scanf("%d%d", &n, &m) == 2 && n && m) {
  25. for(int i = 0; i < n; ++i) scanf("%d", &head[i]);
  26. for(int i = 0; i < m; ++i) scanf("%d", &kill[i]);
  27. sort(head, head + n);
  28. sort(kill, kill + m);
  29. int cnt = 0, cost = 0;
  30. for(int i = 0; i < m; ++i) {
  31. if(kill[i] >= head[cnt]) {
  32. ++cnt;
  33. cost += kill[i];
  34. if(cnt >= n) break;
  35. }
  36. }
  37. if(cnt < n) printf("Loowater is doomed!\n");
  38. else printf("%d\n", cost);
  39. }
  40. return 0;
  41. }

如有不当之处欢迎指出!

UVA - 11292 Dragon of Loowater 贪心的更多相关文章

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

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

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

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

  3. [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 ...

  4. UVa 11292 - Dragon of Loowater(排序贪心)

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

  5. UVa 11292 Dragon of Loowater

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

  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. 贪心/思维题 UVA 11292 The Dragon of Loowater

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

随机推荐

  1. Windows任务计划程序起始于参数自动修改

    Windows任务计划程序建立后,手工运行可以成功,但计划任务自动运行却不能成功,搜索网络,原来是起始于参数没有配置,这个参数的英文名字是start-in.它保证任务计划程序的WorkingDirec ...

  2. Navicat查询结果不能修改的原因

    问题: 开发中常使用Navicat查询数据库,并修改数据库中的值.今天发现查询结果为只读,不能修改.一般连表查不能修改我是知道的,但是单表查居然不能修改. 解决方法: 查了下,有说表是只读,也有说是权 ...

  3. jspf与jsp的区别

    如果想把一个jspf的文件引入(incurred)到一个jsp页面中,只能使用"@include"指令引入 如果使用<jsp:include>引入,jspf文件中的内容 ...

  4. javascript:将URL的参数列表解析为一个对象

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  5. HARBOR 仓库 API功能接口

    1       项目管理 1.1     查看仓库中项目详细信息 curl -u "admin:Harbor12345" -X GET -H "Content-Type: ...

  6. 树莓派小车By 树莓派爱好者ITJoker(通过python socket通信实现树莓派视频小车)(一)

    本文由树莓派爱好者ITJoker 编辑,转载请注明出处.本人也有新浪博客同样是树莓派爱好者ITJoker 所需材料:树莓派2B或者2B以上,L2985n驱动板,若干排线,电池及电池盒,usb无线网卡( ...

  7. SQL Server比较2table字段的差异

    由于项目前后用了2个数据库,需要统计数据库结构的变化,需要统计每个表的变化,由于人工核对挺浪费时间,就写了一点代码: 1.统计表的字段数量(查询表有多少列): select count(name)   ...

  8. JUnit5 技术前瞻

    更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 原文链接:http://www.cnblogs.com/zishi/p/6868495.html   JUnit ...

  9. sap中Excel的模版上传和下载

    一:事物码smw0 二:上传步骤 注:"包"为项目的包的名称. 三:下载代码 l_filename = 'XX.xls'. l_muban = 'z123'. *&---下 ...

  10. Spring整合JMS(二)——三种消息监听器

    原文地址:http://haohaoxuexi.iteye.com/blog/1893676 1.3     消息监听器MessageListener 在Spring整合JMS的应用中我们在定义消息监 ...